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 monitor_printf(mon
, " %s: %" PRId64
,
288 MigrationParameter_lookup
[MIGRATION_PARAMETER_COMPRESS_LEVEL
],
289 params
->compress_level
);
290 monitor_printf(mon
, " %s: %" PRId64
,
291 MigrationParameter_lookup
[MIGRATION_PARAMETER_COMPRESS_THREADS
],
292 params
->compress_threads
);
293 monitor_printf(mon
, " %s: %" PRId64
,
294 MigrationParameter_lookup
[MIGRATION_PARAMETER_DECOMPRESS_THREADS
],
295 params
->decompress_threads
);
296 monitor_printf(mon
, " %s: %" PRId64
,
297 MigrationParameter_lookup
[MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
],
298 params
->cpu_throttle_initial
);
299 monitor_printf(mon
, " %s: %" PRId64
,
300 MigrationParameter_lookup
[MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
],
301 params
->cpu_throttle_increment
);
302 monitor_printf(mon
, " %s: '%s'",
303 MigrationParameter_lookup
[MIGRATION_PARAMETER_TLS_CREDS
],
304 params
->tls_creds
? : "");
305 monitor_printf(mon
, " %s: '%s'",
306 MigrationParameter_lookup
[MIGRATION_PARAMETER_TLS_HOSTNAME
],
307 params
->tls_hostname
? : "");
308 monitor_printf(mon
, "\n");
311 qapi_free_MigrationParameters(params
);
314 void hmp_info_migrate_cache_size(Monitor
*mon
, const QDict
*qdict
)
316 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
317 qmp_query_migrate_cache_size(NULL
) >> 10);
320 void hmp_info_cpus(Monitor
*mon
, const QDict
*qdict
)
322 CpuInfoList
*cpu_list
, *cpu
;
324 cpu_list
= qmp_query_cpus(NULL
);
326 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
329 if (cpu
->value
->CPU
== monitor_get_cpu_index()) {
333 monitor_printf(mon
, "%c CPU #%" PRId64
":", active
, cpu
->value
->CPU
);
335 switch (cpu
->value
->arch
) {
336 case CPU_INFO_ARCH_X86
:
337 monitor_printf(mon
, " pc=0x%016" PRIx64
, cpu
->value
->u
.x86
.pc
);
339 case CPU_INFO_ARCH_PPC
:
340 monitor_printf(mon
, " nip=0x%016" PRIx64
, cpu
->value
->u
.ppc
.nip
);
342 case CPU_INFO_ARCH_SPARC
:
343 monitor_printf(mon
, " pc=0x%016" PRIx64
,
344 cpu
->value
->u
.q_sparc
.pc
);
345 monitor_printf(mon
, " npc=0x%016" PRIx64
,
346 cpu
->value
->u
.q_sparc
.npc
);
348 case CPU_INFO_ARCH_MIPS
:
349 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->u
.q_mips
.PC
);
351 case CPU_INFO_ARCH_TRICORE
:
352 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->u
.tricore
.PC
);
358 if (cpu
->value
->halted
) {
359 monitor_printf(mon
, " (halted)");
362 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
365 qapi_free_CpuInfoList(cpu_list
);
368 static void print_block_info(Monitor
*mon
, BlockInfo
*info
,
369 BlockDeviceInfo
*inserted
, bool verbose
)
371 ImageInfo
*image_info
;
373 assert(!info
|| !info
->has_inserted
|| info
->inserted
== inserted
);
376 monitor_printf(mon
, "%s", info
->device
);
377 if (inserted
&& inserted
->has_node_name
) {
378 monitor_printf(mon
, " (%s)", inserted
->node_name
);
382 monitor_printf(mon
, "%s",
383 inserted
->has_node_name
384 ? inserted
->node_name
389 monitor_printf(mon
, ": %s (%s%s%s)\n",
392 inserted
->ro
? ", read-only" : "",
393 inserted
->encrypted
? ", encrypted" : "");
395 monitor_printf(mon
, ": [not inserted]\n");
399 if (info
->has_io_status
&& info
->io_status
!= BLOCK_DEVICE_IO_STATUS_OK
) {
400 monitor_printf(mon
, " I/O status: %s\n",
401 BlockDeviceIoStatus_lookup
[info
->io_status
]);
404 if (info
->removable
) {
405 monitor_printf(mon
, " Removable device: %slocked, tray %s\n",
406 info
->locked
? "" : "not ",
407 info
->tray_open
? "open" : "closed");
416 monitor_printf(mon
, " Cache mode: %s%s%s\n",
417 inserted
->cache
->writeback
? "writeback" : "writethrough",
418 inserted
->cache
->direct
? ", direct" : "",
419 inserted
->cache
->no_flush
? ", ignore flushes" : "");
421 if (inserted
->has_backing_file
) {
424 "(chain depth: %" PRId64
")\n",
425 inserted
->backing_file
,
426 inserted
->backing_file_depth
);
429 if (inserted
->detect_zeroes
!= BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF
) {
430 monitor_printf(mon
, " Detect zeroes: %s\n",
431 BlockdevDetectZeroesOptions_lookup
[inserted
->detect_zeroes
]);
434 if (inserted
->bps
|| inserted
->bps_rd
|| inserted
->bps_wr
||
435 inserted
->iops
|| inserted
->iops_rd
|| inserted
->iops_wr
)
437 monitor_printf(mon
, " I/O throttling: bps=%" PRId64
438 " bps_rd=%" PRId64
" bps_wr=%" PRId64
440 " bps_rd_max=%" PRId64
441 " bps_wr_max=%" PRId64
442 " iops=%" PRId64
" iops_rd=%" PRId64
445 " iops_rd_max=%" PRId64
446 " iops_wr_max=%" PRId64
447 " iops_size=%" PRId64
453 inserted
->bps_rd_max
,
454 inserted
->bps_wr_max
,
459 inserted
->iops_rd_max
,
460 inserted
->iops_wr_max
,
466 monitor_printf(mon
, "\nImages:\n");
467 image_info
= inserted
->image
;
469 bdrv_image_info_dump((fprintf_function
)monitor_printf
,
471 if (image_info
->has_backing_image
) {
472 image_info
= image_info
->backing_image
;
480 void hmp_info_block(Monitor
*mon
, const QDict
*qdict
)
482 BlockInfoList
*block_list
, *info
;
483 BlockDeviceInfoList
*blockdev_list
, *blockdev
;
484 const char *device
= qdict_get_try_str(qdict
, "device");
485 bool verbose
= qdict_get_try_bool(qdict
, "verbose", false);
486 bool nodes
= qdict_get_try_bool(qdict
, "nodes", false);
487 bool printed
= false;
489 /* Print BlockBackend information */
491 block_list
= qmp_query_block(NULL
);
496 for (info
= block_list
; info
; info
= info
->next
) {
497 if (device
&& strcmp(device
, info
->value
->device
)) {
501 if (info
!= block_list
) {
502 monitor_printf(mon
, "\n");
505 print_block_info(mon
, info
->value
, info
->value
->has_inserted
506 ? info
->value
->inserted
: NULL
,
511 qapi_free_BlockInfoList(block_list
);
513 if ((!device
&& !nodes
) || printed
) {
517 /* Print node information */
518 blockdev_list
= qmp_query_named_block_nodes(NULL
);
519 for (blockdev
= blockdev_list
; blockdev
; blockdev
= blockdev
->next
) {
520 assert(blockdev
->value
->has_node_name
);
521 if (device
&& strcmp(device
, blockdev
->value
->node_name
)) {
525 if (blockdev
!= blockdev_list
) {
526 monitor_printf(mon
, "\n");
529 print_block_info(mon
, NULL
, blockdev
->value
, verbose
);
531 qapi_free_BlockDeviceInfoList(blockdev_list
);
534 void hmp_info_blockstats(Monitor
*mon
, const QDict
*qdict
)
536 BlockStatsList
*stats_list
, *stats
;
538 stats_list
= qmp_query_blockstats(false, false, NULL
);
540 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
541 if (!stats
->value
->has_device
) {
545 monitor_printf(mon
, "%s:", stats
->value
->device
);
546 monitor_printf(mon
, " rd_bytes=%" PRId64
548 " rd_operations=%" PRId64
549 " wr_operations=%" PRId64
550 " flush_operations=%" PRId64
551 " wr_total_time_ns=%" PRId64
552 " rd_total_time_ns=%" PRId64
553 " flush_total_time_ns=%" PRId64
554 " rd_merged=%" PRId64
555 " wr_merged=%" PRId64
556 " idle_time_ns=%" PRId64
558 stats
->value
->stats
->rd_bytes
,
559 stats
->value
->stats
->wr_bytes
,
560 stats
->value
->stats
->rd_operations
,
561 stats
->value
->stats
->wr_operations
,
562 stats
->value
->stats
->flush_operations
,
563 stats
->value
->stats
->wr_total_time_ns
,
564 stats
->value
->stats
->rd_total_time_ns
,
565 stats
->value
->stats
->flush_total_time_ns
,
566 stats
->value
->stats
->rd_merged
,
567 stats
->value
->stats
->wr_merged
,
568 stats
->value
->stats
->idle_time_ns
);
571 qapi_free_BlockStatsList(stats_list
);
574 void hmp_info_vnc(Monitor
*mon
, const QDict
*qdict
)
578 VncClientInfoList
*client
;
580 info
= qmp_query_vnc(&err
);
582 error_report_err(err
);
586 if (!info
->enabled
) {
587 monitor_printf(mon
, "Server: disabled\n");
591 monitor_printf(mon
, "Server:\n");
592 if (info
->has_host
&& info
->has_service
) {
593 monitor_printf(mon
, " address: %s:%s\n", info
->host
, info
->service
);
595 if (info
->has_auth
) {
596 monitor_printf(mon
, " auth: %s\n", info
->auth
);
599 if (!info
->has_clients
|| info
->clients
== NULL
) {
600 monitor_printf(mon
, "Client: none\n");
602 for (client
= info
->clients
; client
; client
= client
->next
) {
603 monitor_printf(mon
, "Client:\n");
604 monitor_printf(mon
, " address: %s:%s\n",
606 client
->value
->service
);
607 monitor_printf(mon
, " x509_dname: %s\n",
608 client
->value
->x509_dname
?
609 client
->value
->x509_dname
: "none");
610 monitor_printf(mon
, " username: %s\n",
611 client
->value
->has_sasl_username
?
612 client
->value
->sasl_username
: "none");
617 qapi_free_VncInfo(info
);
621 void hmp_info_spice(Monitor
*mon
, const QDict
*qdict
)
623 SpiceChannelList
*chan
;
625 const char *channel_name
;
626 const char * const channel_names
[] = {
627 [SPICE_CHANNEL_MAIN
] = "main",
628 [SPICE_CHANNEL_DISPLAY
] = "display",
629 [SPICE_CHANNEL_INPUTS
] = "inputs",
630 [SPICE_CHANNEL_CURSOR
] = "cursor",
631 [SPICE_CHANNEL_PLAYBACK
] = "playback",
632 [SPICE_CHANNEL_RECORD
] = "record",
633 [SPICE_CHANNEL_TUNNEL
] = "tunnel",
634 [SPICE_CHANNEL_SMARTCARD
] = "smartcard",
635 [SPICE_CHANNEL_USBREDIR
] = "usbredir",
636 [SPICE_CHANNEL_PORT
] = "port",
638 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
639 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
640 * as quick fix for build failures with older versions. */
641 [SPICE_CHANNEL_WEBDAV
] = "webdav",
645 info
= qmp_query_spice(NULL
);
647 if (!info
->enabled
) {
648 monitor_printf(mon
, "Server: disabled\n");
652 monitor_printf(mon
, "Server:\n");
653 if (info
->has_port
) {
654 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
655 info
->host
, info
->port
);
657 if (info
->has_tls_port
) {
658 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
659 info
->host
, info
->tls_port
);
661 monitor_printf(mon
, " migrated: %s\n",
662 info
->migrated
? "true" : "false");
663 monitor_printf(mon
, " auth: %s\n", info
->auth
);
664 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
665 monitor_printf(mon
, " mouse-mode: %s\n",
666 SpiceQueryMouseMode_lookup
[info
->mouse_mode
]);
668 if (!info
->has_channels
|| info
->channels
== NULL
) {
669 monitor_printf(mon
, "Channels: none\n");
671 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
672 monitor_printf(mon
, "Channel:\n");
673 monitor_printf(mon
, " address: %s:%s%s\n",
674 chan
->value
->host
, chan
->value
->port
,
675 chan
->value
->tls
? " [tls]" : "");
676 monitor_printf(mon
, " session: %" PRId64
"\n",
677 chan
->value
->connection_id
);
678 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
679 chan
->value
->channel_type
, chan
->value
->channel_id
);
681 channel_name
= "unknown";
682 if (chan
->value
->channel_type
> 0 &&
683 chan
->value
->channel_type
< ARRAY_SIZE(channel_names
) &&
684 channel_names
[chan
->value
->channel_type
]) {
685 channel_name
= channel_names
[chan
->value
->channel_type
];
688 monitor_printf(mon
, " channel name: %s\n", channel_name
);
693 qapi_free_SpiceInfo(info
);
697 void hmp_info_balloon(Monitor
*mon
, const QDict
*qdict
)
702 info
= qmp_query_balloon(&err
);
704 error_report_err(err
);
708 monitor_printf(mon
, "balloon: actual=%" PRId64
"\n", info
->actual
>> 20);
710 qapi_free_BalloonInfo(info
);
713 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
715 PciMemoryRegionList
*region
;
717 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
718 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
719 dev
->slot
, dev
->function
);
720 monitor_printf(mon
, " ");
722 if (dev
->class_info
->has_desc
) {
723 monitor_printf(mon
, "%s", dev
->class_info
->desc
);
725 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
->q_class
);
728 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
729 dev
->id
->vendor
, dev
->id
->device
);
732 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
735 if (dev
->has_pci_bridge
) {
736 monitor_printf(mon
, " BUS %" PRId64
".\n",
737 dev
->pci_bridge
->bus
->number
);
738 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
739 dev
->pci_bridge
->bus
->secondary
);
740 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
741 dev
->pci_bridge
->bus
->subordinate
);
743 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
744 dev
->pci_bridge
->bus
->io_range
->base
,
745 dev
->pci_bridge
->bus
->io_range
->limit
);
748 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
749 dev
->pci_bridge
->bus
->memory_range
->base
,
750 dev
->pci_bridge
->bus
->memory_range
->limit
);
752 monitor_printf(mon
, " prefetchable memory range "
753 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
754 dev
->pci_bridge
->bus
->prefetchable_range
->base
,
755 dev
->pci_bridge
->bus
->prefetchable_range
->limit
);
758 for (region
= dev
->regions
; region
; region
= region
->next
) {
761 addr
= region
->value
->address
;
762 size
= region
->value
->size
;
764 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
766 if (!strcmp(region
->value
->type
, "io")) {
767 monitor_printf(mon
, "I/O at 0x%04" PRIx64
768 " [0x%04" PRIx64
"].\n",
769 addr
, addr
+ size
- 1);
771 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
772 " [0x%08" PRIx64
"].\n",
773 region
->value
->mem_type_64
? 64 : 32,
774 region
->value
->prefetch
? " prefetchable" : "",
775 addr
, addr
+ size
- 1);
779 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
781 if (dev
->has_pci_bridge
) {
782 if (dev
->pci_bridge
->has_devices
) {
783 PciDeviceInfoList
*cdev
;
784 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
785 hmp_info_pci_device(mon
, cdev
->value
);
791 static int hmp_info_irq_foreach(Object
*obj
, void *opaque
)
793 InterruptStatsProvider
*intc
;
794 InterruptStatsProviderClass
*k
;
795 Monitor
*mon
= opaque
;
797 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
798 intc
= INTERRUPT_STATS_PROVIDER(obj
);
799 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
800 uint64_t *irq_counts
;
801 unsigned int nb_irqs
, i
;
802 if (k
->get_statistics
&&
803 k
->get_statistics(intc
, &irq_counts
, &nb_irqs
)) {
805 monitor_printf(mon
, "IRQ statistics for %s:\n",
806 object_get_typename(obj
));
807 for (i
= 0; i
< nb_irqs
; i
++) {
808 if (irq_counts
[i
] > 0) {
809 monitor_printf(mon
, "%2d: %" PRId64
"\n", i
,
815 monitor_printf(mon
, "IRQ statistics not available for %s.\n",
816 object_get_typename(obj
));
823 void hmp_info_irq(Monitor
*mon
, const QDict
*qdict
)
825 object_child_foreach_recursive(object_get_root(),
826 hmp_info_irq_foreach
, mon
);
829 static int hmp_info_pic_foreach(Object
*obj
, void *opaque
)
831 InterruptStatsProvider
*intc
;
832 InterruptStatsProviderClass
*k
;
833 Monitor
*mon
= opaque
;
835 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
836 intc
= INTERRUPT_STATS_PROVIDER(obj
);
837 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
839 k
->print_info(intc
, mon
);
841 monitor_printf(mon
, "Interrupt controller information not available for %s.\n",
842 object_get_typename(obj
));
849 void hmp_info_pic(Monitor
*mon
, const QDict
*qdict
)
851 object_child_foreach_recursive(object_get_root(),
852 hmp_info_pic_foreach
, mon
);
855 void hmp_info_pci(Monitor
*mon
, const QDict
*qdict
)
857 PciInfoList
*info_list
, *info
;
860 info_list
= qmp_query_pci(&err
);
862 monitor_printf(mon
, "PCI devices not supported\n");
867 for (info
= info_list
; info
; info
= info
->next
) {
868 PciDeviceInfoList
*dev
;
870 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
871 hmp_info_pci_device(mon
, dev
->value
);
875 qapi_free_PciInfoList(info_list
);
878 void hmp_info_block_jobs(Monitor
*mon
, const QDict
*qdict
)
880 BlockJobInfoList
*list
;
883 list
= qmp_query_block_jobs(&err
);
887 monitor_printf(mon
, "No active jobs\n");
892 if (strcmp(list
->value
->type
, "stream") == 0) {
893 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
894 " of %" PRId64
" bytes, speed limit %" PRId64
901 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
902 " of %" PRId64
" bytes, speed limit %" PRId64
913 qapi_free_BlockJobInfoList(list
);
916 void hmp_info_tpm(Monitor
*mon
, const QDict
*qdict
)
918 TPMInfoList
*info_list
, *info
;
921 TPMPassthroughOptions
*tpo
;
923 info_list
= qmp_query_tpm(&err
);
925 monitor_printf(mon
, "TPM device not supported\n");
931 monitor_printf(mon
, "TPM device:\n");
934 for (info
= info_list
; info
; info
= info
->next
) {
935 TPMInfo
*ti
= info
->value
;
936 monitor_printf(mon
, " tpm%d: model=%s\n",
937 c
, TpmModel_lookup
[ti
->model
]);
939 monitor_printf(mon
, " \\ %s: type=%s",
940 ti
->id
, TpmTypeOptionsKind_lookup
[ti
->options
->type
]);
942 switch (ti
->options
->type
) {
943 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH
:
944 tpo
= ti
->options
->u
.passthrough
.data
;
945 monitor_printf(mon
, "%s%s%s%s",
946 tpo
->has_path
? ",path=" : "",
947 tpo
->has_path
? tpo
->path
: "",
948 tpo
->has_cancel_path
? ",cancel-path=" : "",
949 tpo
->has_cancel_path
? tpo
->cancel_path
: "");
951 case TPM_TYPE_OPTIONS_KIND__MAX
:
954 monitor_printf(mon
, "\n");
957 qapi_free_TPMInfoList(info_list
);
960 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
962 monitor_suspend(mon
);
966 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
971 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
973 qmp_system_reset(NULL
);
976 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
978 qmp_system_powerdown(NULL
);
981 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
985 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
986 use it are converted to the QAPI */
987 cpu_index
= qdict_get_int(qdict
, "index");
988 if (monitor_set_cpu(cpu_index
) < 0) {
989 monitor_printf(mon
, "invalid CPU index\n");
993 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
995 uint32_t size
= qdict_get_int(qdict
, "size");
996 const char *filename
= qdict_get_str(qdict
, "filename");
997 uint64_t addr
= qdict_get_int(qdict
, "val");
1000 qmp_memsave(addr
, size
, filename
, true, monitor_get_cpu_index(), &err
);
1001 hmp_handle_error(mon
, &err
);
1004 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
1006 uint32_t size
= qdict_get_int(qdict
, "size");
1007 const char *filename
= qdict_get_str(qdict
, "filename");
1008 uint64_t addr
= qdict_get_int(qdict
, "val");
1011 qmp_pmemsave(addr
, size
, filename
, &err
);
1012 hmp_handle_error(mon
, &err
);
1015 void hmp_ringbuf_write(Monitor
*mon
, const QDict
*qdict
)
1017 const char *chardev
= qdict_get_str(qdict
, "device");
1018 const char *data
= qdict_get_str(qdict
, "data");
1021 qmp_ringbuf_write(chardev
, data
, false, 0, &err
);
1023 hmp_handle_error(mon
, &err
);
1026 void hmp_ringbuf_read(Monitor
*mon
, const QDict
*qdict
)
1028 uint32_t size
= qdict_get_int(qdict
, "size");
1029 const char *chardev
= qdict_get_str(qdict
, "device");
1034 data
= qmp_ringbuf_read(chardev
, size
, false, 0, &err
);
1036 error_report_err(err
);
1040 for (i
= 0; data
[i
]; i
++) {
1041 unsigned char ch
= data
[i
];
1044 monitor_printf(mon
, "\\\\");
1045 } else if ((ch
< 0x20 && ch
!= '\n' && ch
!= '\t') || ch
== 0x7F) {
1046 monitor_printf(mon
, "\\u%04X", ch
);
1048 monitor_printf(mon
, "%c", ch
);
1052 monitor_printf(mon
, "\n");
1056 static void hmp_cont_cb(void *opaque
, int err
)
1063 static bool key_is_missing(const BlockInfo
*bdev
)
1065 return (bdev
->inserted
&& bdev
->inserted
->encryption_key_missing
);
1068 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
1070 BlockInfoList
*bdev_list
, *bdev
;
1073 bdev_list
= qmp_query_block(NULL
);
1074 for (bdev
= bdev_list
; bdev
; bdev
= bdev
->next
) {
1075 if (key_is_missing(bdev
->value
)) {
1076 monitor_read_block_device_key(mon
, bdev
->value
->device
,
1083 hmp_handle_error(mon
, &err
);
1086 qapi_free_BlockInfoList(bdev_list
);
1089 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
1091 qmp_system_wakeup(NULL
);
1094 void hmp_nmi(Monitor
*mon
, const QDict
*qdict
)
1098 qmp_inject_nmi(&err
);
1099 hmp_handle_error(mon
, &err
);
1102 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
1104 const char *name
= qdict_get_str(qdict
, "name");
1105 bool up
= qdict_get_bool(qdict
, "up");
1108 qmp_set_link(name
, up
, &err
);
1109 hmp_handle_error(mon
, &err
);
1112 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
1114 const char *device
= qdict_get_str(qdict
, "device");
1115 const char *password
= qdict_get_str(qdict
, "password");
1118 qmp_block_passwd(true, device
, false, NULL
, password
, &err
);
1119 hmp_handle_error(mon
, &err
);
1122 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
1124 int64_t value
= qdict_get_int(qdict
, "value");
1127 qmp_balloon(value
, &err
);
1129 error_report_err(err
);
1133 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
1135 const char *device
= qdict_get_str(qdict
, "device");
1136 int64_t size
= qdict_get_int(qdict
, "size");
1139 qmp_block_resize(true, device
, false, NULL
, size
, &err
);
1140 hmp_handle_error(mon
, &err
);
1143 void hmp_drive_mirror(Monitor
*mon
, const QDict
*qdict
)
1145 const char *filename
= qdict_get_str(qdict
, "target");
1146 const char *format
= qdict_get_try_str(qdict
, "format");
1147 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1148 bool full
= qdict_get_try_bool(qdict
, "full", false);
1150 DriveMirror mirror
= {
1151 .device
= (char *)qdict_get_str(qdict
, "device"),
1152 .target
= (char *)filename
,
1153 .has_format
= !!format
,
1154 .format
= (char *)format
,
1155 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1157 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
1162 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1163 hmp_handle_error(mon
, &err
);
1166 qmp_drive_mirror(&mirror
, &err
);
1167 hmp_handle_error(mon
, &err
);
1170 void hmp_drive_backup(Monitor
*mon
, const QDict
*qdict
)
1172 const char *device
= qdict_get_str(qdict
, "device");
1173 const char *filename
= qdict_get_str(qdict
, "target");
1174 const char *format
= qdict_get_try_str(qdict
, "format");
1175 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1176 bool full
= qdict_get_try_bool(qdict
, "full", false);
1177 bool compress
= qdict_get_try_bool(qdict
, "compress", false);
1179 DriveBackup backup
= {
1180 .device
= (char *)device
,
1181 .target
= (char *)filename
,
1182 .has_format
= !!format
,
1183 .format
= (char *)format
,
1184 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1186 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
1187 .has_compress
= !!compress
,
1188 .compress
= compress
,
1192 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1193 hmp_handle_error(mon
, &err
);
1197 qmp_drive_backup(&backup
, &err
);
1198 hmp_handle_error(mon
, &err
);
1201 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
1203 const char *device
= qdict_get_str(qdict
, "device");
1204 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
1205 const char *format
= qdict_get_try_str(qdict
, "format");
1206 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1207 enum NewImageMode mode
;
1211 /* In the future, if 'snapshot-file' is not specified, the snapshot
1212 will be taken internally. Today it's actually required. */
1213 error_setg(&err
, QERR_MISSING_PARAMETER
, "snapshot-file");
1214 hmp_handle_error(mon
, &err
);
1218 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
1219 qmp_blockdev_snapshot_sync(true, device
, false, NULL
,
1220 filename
, false, NULL
,
1223 hmp_handle_error(mon
, &err
);
1226 void hmp_snapshot_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1228 const char *device
= qdict_get_str(qdict
, "device");
1229 const char *name
= qdict_get_str(qdict
, "name");
1232 qmp_blockdev_snapshot_internal_sync(device
, name
, &err
);
1233 hmp_handle_error(mon
, &err
);
1236 void hmp_snapshot_delete_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1238 const char *device
= qdict_get_str(qdict
, "device");
1239 const char *name
= qdict_get_str(qdict
, "name");
1240 const char *id
= qdict_get_try_str(qdict
, "id");
1243 qmp_blockdev_snapshot_delete_internal_sync(device
, !!id
, id
,
1245 hmp_handle_error(mon
, &err
);
1248 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
1250 qmp_migrate_cancel(NULL
);
1253 void hmp_migrate_incoming(Monitor
*mon
, const QDict
*qdict
)
1256 const char *uri
= qdict_get_str(qdict
, "uri");
1258 qmp_migrate_incoming(uri
, &err
);
1260 hmp_handle_error(mon
, &err
);
1263 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
1265 double value
= qdict_get_double(qdict
, "value");
1266 qmp_migrate_set_downtime(value
, NULL
);
1269 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
1271 int64_t value
= qdict_get_int(qdict
, "value");
1274 qmp_migrate_set_cache_size(value
, &err
);
1276 error_report_err(err
);
1281 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
1283 int64_t value
= qdict_get_int(qdict
, "value");
1284 qmp_migrate_set_speed(value
, NULL
);
1287 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
1289 const char *cap
= qdict_get_str(qdict
, "capability");
1290 bool state
= qdict_get_bool(qdict
, "state");
1292 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
1295 for (i
= 0; i
< MIGRATION_CAPABILITY__MAX
; i
++) {
1296 if (strcmp(cap
, MigrationCapability_lookup
[i
]) == 0) {
1297 caps
->value
= g_malloc0(sizeof(*caps
->value
));
1298 caps
->value
->capability
= i
;
1299 caps
->value
->state
= state
;
1301 qmp_migrate_set_capabilities(caps
, &err
);
1306 if (i
== MIGRATION_CAPABILITY__MAX
) {
1307 error_setg(&err
, QERR_INVALID_PARAMETER
, cap
);
1310 qapi_free_MigrationCapabilityStatusList(caps
);
1313 error_report_err(err
);
1317 void hmp_migrate_set_parameter(Monitor
*mon
, const QDict
*qdict
)
1319 const char *param
= qdict_get_str(qdict
, "parameter");
1320 const char *valuestr
= qdict_get_str(qdict
, "value");
1323 bool has_compress_level
= false;
1324 bool has_compress_threads
= false;
1325 bool has_decompress_threads
= false;
1326 bool has_cpu_throttle_initial
= false;
1327 bool has_cpu_throttle_increment
= false;
1328 bool has_tls_creds
= false;
1329 bool has_tls_hostname
= false;
1330 bool use_int_value
= false;
1333 for (i
= 0; i
< MIGRATION_PARAMETER__MAX
; i
++) {
1334 if (strcmp(param
, MigrationParameter_lookup
[i
]) == 0) {
1336 case MIGRATION_PARAMETER_COMPRESS_LEVEL
:
1337 has_compress_level
= true;
1338 use_int_value
= true;
1340 case MIGRATION_PARAMETER_COMPRESS_THREADS
:
1341 has_compress_threads
= true;
1342 use_int_value
= true;
1344 case MIGRATION_PARAMETER_DECOMPRESS_THREADS
:
1345 has_decompress_threads
= true;
1346 use_int_value
= true;
1348 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
:
1349 has_cpu_throttle_initial
= true;
1350 use_int_value
= true;
1352 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
:
1353 has_cpu_throttle_increment
= true;
1355 case MIGRATION_PARAMETER_TLS_CREDS
:
1356 has_tls_creds
= true;
1358 case MIGRATION_PARAMETER_TLS_HOSTNAME
:
1359 has_tls_hostname
= true;
1363 if (use_int_value
) {
1364 if (qemu_strtol(valuestr
, NULL
, 10, &valueint
) < 0) {
1365 error_setg(&err
, "Unable to parse '%s' as an int",
1371 qmp_migrate_set_parameters(has_compress_level
, valueint
,
1372 has_compress_threads
, valueint
,
1373 has_decompress_threads
, valueint
,
1374 has_cpu_throttle_initial
, valueint
,
1375 has_cpu_throttle_increment
, valueint
,
1376 has_tls_creds
, valuestr
,
1377 has_tls_hostname
, valuestr
,
1383 if (i
== MIGRATION_PARAMETER__MAX
) {
1384 error_setg(&err
, QERR_INVALID_PARAMETER
, param
);
1389 error_report_err(err
);
1393 void hmp_client_migrate_info(Monitor
*mon
, const QDict
*qdict
)
1396 const char *protocol
= qdict_get_str(qdict
, "protocol");
1397 const char *hostname
= qdict_get_str(qdict
, "hostname");
1398 bool has_port
= qdict_haskey(qdict
, "port");
1399 int port
= qdict_get_try_int(qdict
, "port", -1);
1400 bool has_tls_port
= qdict_haskey(qdict
, "tls-port");
1401 int tls_port
= qdict_get_try_int(qdict
, "tls-port", -1);
1402 const char *cert_subject
= qdict_get_try_str(qdict
, "cert-subject");
1404 qmp_client_migrate_info(protocol
, hostname
,
1405 has_port
, port
, has_tls_port
, tls_port
,
1406 !!cert_subject
, cert_subject
, &err
);
1407 hmp_handle_error(mon
, &err
);
1410 void hmp_migrate_start_postcopy(Monitor
*mon
, const QDict
*qdict
)
1413 qmp_migrate_start_postcopy(&err
);
1414 hmp_handle_error(mon
, &err
);
1417 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
1419 const char *protocol
= qdict_get_str(qdict
, "protocol");
1420 const char *password
= qdict_get_str(qdict
, "password");
1421 const char *connected
= qdict_get_try_str(qdict
, "connected");
1424 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
1425 hmp_handle_error(mon
, &err
);
1428 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
1430 const char *protocol
= qdict_get_str(qdict
, "protocol");
1431 const char *whenstr
= qdict_get_str(qdict
, "time");
1434 qmp_expire_password(protocol
, whenstr
, &err
);
1435 hmp_handle_error(mon
, &err
);
1438 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
1440 bool force
= qdict_get_try_bool(qdict
, "force", false);
1441 const char *device
= qdict_get_str(qdict
, "device");
1444 qmp_eject(true, device
, false, NULL
, true, force
, &err
);
1445 hmp_handle_error(mon
, &err
);
1448 static void hmp_change_read_arg(void *opaque
, const char *password
,
1449 void *readline_opaque
)
1451 qmp_change_vnc_password(password
, NULL
);
1452 monitor_read_command(opaque
, 1);
1455 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
1457 const char *device
= qdict_get_str(qdict
, "device");
1458 const char *target
= qdict_get_str(qdict
, "target");
1459 const char *arg
= qdict_get_try_str(qdict
, "arg");
1460 const char *read_only
= qdict_get_try_str(qdict
, "read-only-mode");
1461 BlockdevChangeReadOnlyMode read_only_mode
= 0;
1464 if (strcmp(device
, "vnc") == 0) {
1467 "Parameter 'read-only-mode' is invalid for VNC\n");
1470 if (strcmp(target
, "passwd") == 0 ||
1471 strcmp(target
, "password") == 0) {
1473 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
1477 qmp_change("vnc", target
, !!arg
, arg
, &err
);
1481 qapi_enum_parse(BlockdevChangeReadOnlyMode_lookup
,
1482 read_only
, BLOCKDEV_CHANGE_READ_ONLY_MODE__MAX
,
1483 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN
, &err
);
1485 hmp_handle_error(mon
, &err
);
1490 qmp_blockdev_change_medium(true, device
, false, NULL
, target
,
1491 !!arg
, arg
, !!read_only
, read_only_mode
,
1494 error_get_class(err
) == ERROR_CLASS_DEVICE_ENCRYPTED
) {
1496 monitor_read_block_device_key(mon
, device
, NULL
, NULL
);
1501 hmp_handle_error(mon
, &err
);
1504 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
1507 BlockIOThrottle throttle
= {
1508 .device
= (char *) qdict_get_str(qdict
, "device"),
1509 .bps
= qdict_get_int(qdict
, "bps"),
1510 .bps_rd
= qdict_get_int(qdict
, "bps_rd"),
1511 .bps_wr
= qdict_get_int(qdict
, "bps_wr"),
1512 .iops
= qdict_get_int(qdict
, "iops"),
1513 .iops_rd
= qdict_get_int(qdict
, "iops_rd"),
1514 .iops_wr
= qdict_get_int(qdict
, "iops_wr"),
1517 qmp_block_set_io_throttle(&throttle
, &err
);
1518 hmp_handle_error(mon
, &err
);
1521 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
1523 Error
*error
= NULL
;
1524 const char *device
= qdict_get_str(qdict
, "device");
1525 const char *base
= qdict_get_try_str(qdict
, "base");
1526 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
1528 qmp_block_stream(false, NULL
, device
, base
!= NULL
, base
, false, NULL
,
1529 qdict_haskey(qdict
, "speed"), speed
,
1530 true, BLOCKDEV_ON_ERROR_REPORT
, &error
);
1532 hmp_handle_error(mon
, &error
);
1535 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
1537 Error
*error
= NULL
;
1538 const char *device
= qdict_get_str(qdict
, "device");
1539 int64_t value
= qdict_get_int(qdict
, "speed");
1541 qmp_block_job_set_speed(device
, value
, &error
);
1543 hmp_handle_error(mon
, &error
);
1546 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
1548 Error
*error
= NULL
;
1549 const char *device
= qdict_get_str(qdict
, "device");
1550 bool force
= qdict_get_try_bool(qdict
, "force", false);
1552 qmp_block_job_cancel(device
, true, force
, &error
);
1554 hmp_handle_error(mon
, &error
);
1557 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
1559 Error
*error
= NULL
;
1560 const char *device
= qdict_get_str(qdict
, "device");
1562 qmp_block_job_pause(device
, &error
);
1564 hmp_handle_error(mon
, &error
);
1567 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
1569 Error
*error
= NULL
;
1570 const char *device
= qdict_get_str(qdict
, "device");
1572 qmp_block_job_resume(device
, &error
);
1574 hmp_handle_error(mon
, &error
);
1577 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
1579 Error
*error
= NULL
;
1580 const char *device
= qdict_get_str(qdict
, "device");
1582 qmp_block_job_complete(device
, &error
);
1584 hmp_handle_error(mon
, &error
);
1587 typedef struct HMPMigrationStatus
1591 bool is_block_migration
;
1592 } HMPMigrationStatus
;
1594 static void hmp_migrate_status_cb(void *opaque
)
1596 HMPMigrationStatus
*status
= opaque
;
1597 MigrationInfo
*info
;
1599 info
= qmp_query_migrate(NULL
);
1600 if (!info
->has_status
|| info
->status
== MIGRATION_STATUS_ACTIVE
||
1601 info
->status
== MIGRATION_STATUS_SETUP
) {
1602 if (info
->has_disk
) {
1605 if (info
->disk
->remaining
) {
1606 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1611 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1612 monitor_flush(status
->mon
);
1615 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1000);
1617 if (status
->is_block_migration
) {
1618 monitor_printf(status
->mon
, "\n");
1620 if (info
->has_error_desc
) {
1621 error_report("%s", info
->error_desc
);
1623 monitor_resume(status
->mon
);
1624 timer_del(status
->timer
);
1628 qapi_free_MigrationInfo(info
);
1631 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1633 bool detach
= qdict_get_try_bool(qdict
, "detach", false);
1634 bool blk
= qdict_get_try_bool(qdict
, "blk", false);
1635 bool inc
= qdict_get_try_bool(qdict
, "inc", false);
1636 const char *uri
= qdict_get_str(qdict
, "uri");
1639 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
1641 error_report_err(err
);
1646 HMPMigrationStatus
*status
;
1648 if (monitor_suspend(mon
) < 0) {
1649 monitor_printf(mon
, "terminal does not allow synchronous "
1650 "migration, continuing detached\n");
1654 status
= g_malloc0(sizeof(*status
));
1656 status
->is_block_migration
= blk
|| inc
;
1657 status
->timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, hmp_migrate_status_cb
,
1659 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
1663 void hmp_device_add(Monitor
*mon
, const QDict
*qdict
)
1667 qmp_device_add((QDict
*)qdict
, NULL
, &err
);
1668 hmp_handle_error(mon
, &err
);
1671 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1673 const char *id
= qdict_get_str(qdict
, "id");
1676 qmp_device_del(id
, &err
);
1677 hmp_handle_error(mon
, &err
);
1680 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1683 bool paging
= qdict_get_try_bool(qdict
, "paging", false);
1684 bool zlib
= qdict_get_try_bool(qdict
, "zlib", false);
1685 bool lzo
= qdict_get_try_bool(qdict
, "lzo", false);
1686 bool snappy
= qdict_get_try_bool(qdict
, "snappy", false);
1687 const char *file
= qdict_get_str(qdict
, "filename");
1688 bool has_begin
= qdict_haskey(qdict
, "begin");
1689 bool has_length
= qdict_haskey(qdict
, "length");
1690 bool has_detach
= qdict_haskey(qdict
, "detach");
1693 bool detach
= false;
1694 enum DumpGuestMemoryFormat dump_format
= DUMP_GUEST_MEMORY_FORMAT_ELF
;
1697 if (zlib
+ lzo
+ snappy
> 1) {
1698 error_setg(&err
, "only one of '-z|-l|-s' can be set");
1699 hmp_handle_error(mon
, &err
);
1704 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB
;
1708 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO
;
1712 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY
;
1716 begin
= qdict_get_int(qdict
, "begin");
1719 length
= qdict_get_int(qdict
, "length");
1722 detach
= qdict_get_bool(qdict
, "detach");
1725 prot
= g_strconcat("file:", file
, NULL
);
1727 qmp_dump_guest_memory(paging
, prot
, true, detach
, has_begin
, begin
,
1728 has_length
, length
, true, dump_format
, &err
);
1729 hmp_handle_error(mon
, &err
);
1733 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
1738 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
1743 netdev_add(opts
, &err
);
1745 qemu_opts_del(opts
);
1749 hmp_handle_error(mon
, &err
);
1752 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
1754 const char *id
= qdict_get_str(qdict
, "id");
1757 qmp_netdev_del(id
, &err
);
1758 hmp_handle_error(mon
, &err
);
1761 void hmp_object_add(Monitor
*mon
, const QDict
*qdict
)
1768 opts
= qemu_opts_from_qdict(qemu_find_opts("object"), qdict
, &err
);
1770 hmp_handle_error(mon
, &err
);
1774 v
= opts_visitor_new(opts
);
1775 obj
= user_creatable_add(qdict
, v
, &err
);
1777 qemu_opts_del(opts
);
1780 hmp_handle_error(mon
, &err
);
1787 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
1789 const char *fdname
= qdict_get_str(qdict
, "fdname");
1792 qmp_getfd(fdname
, &err
);
1793 hmp_handle_error(mon
, &err
);
1796 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
1798 const char *fdname
= qdict_get_str(qdict
, "fdname");
1801 qmp_closefd(fdname
, &err
);
1802 hmp_handle_error(mon
, &err
);
1805 void hmp_sendkey(Monitor
*mon
, const QDict
*qdict
)
1807 const char *keys
= qdict_get_str(qdict
, "keys");
1808 KeyValueList
*keylist
, *head
= NULL
, *tmp
= NULL
;
1809 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
1810 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
1816 separator
= strchr(keys
, '-');
1817 keyname_len
= separator
? separator
- keys
: strlen(keys
);
1819 /* Be compatible with old interface, convert user inputted "<" */
1820 if (keys
[0] == '<' && keyname_len
== 1) {
1825 keylist
= g_malloc0(sizeof(*keylist
));
1826 keylist
->value
= g_malloc0(sizeof(*keylist
->value
));
1832 tmp
->next
= keylist
;
1836 if (strstart(keys
, "0x", NULL
)) {
1838 int value
= strtoul(keys
, &endp
, 0);
1839 assert(endp
<= keys
+ keyname_len
);
1840 if (endp
!= keys
+ keyname_len
) {
1843 keylist
->value
->type
= KEY_VALUE_KIND_NUMBER
;
1844 keylist
->value
->u
.number
.data
= value
;
1846 int idx
= index_from_key(keys
, keyname_len
);
1847 if (idx
== Q_KEY_CODE__MAX
) {
1850 keylist
->value
->type
= KEY_VALUE_KIND_QCODE
;
1851 keylist
->value
->u
.qcode
.data
= idx
;
1857 keys
= separator
+ 1;
1860 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
1861 hmp_handle_error(mon
, &err
);
1864 qapi_free_KeyValueList(head
);
1868 monitor_printf(mon
, "invalid parameter: %.*s\n", keyname_len
, keys
);
1872 void hmp_screendump(Monitor
*mon
, const QDict
*qdict
)
1874 const char *filename
= qdict_get_str(qdict
, "filename");
1877 qmp_screendump(filename
, &err
);
1878 hmp_handle_error(mon
, &err
);
1881 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
1883 const char *uri
= qdict_get_str(qdict
, "uri");
1884 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
1885 bool all
= qdict_get_try_bool(qdict
, "all", false);
1886 Error
*local_err
= NULL
;
1887 BlockInfoList
*block_list
, *info
;
1888 SocketAddress
*addr
;
1890 if (writable
&& !all
) {
1891 error_setg(&local_err
, "-w only valid together with -a");
1895 /* First check if the address is valid and start the server. */
1896 addr
= socket_parse(uri
, &local_err
);
1897 if (local_err
!= NULL
) {
1901 qmp_nbd_server_start(addr
, false, NULL
, &local_err
);
1902 qapi_free_SocketAddress(addr
);
1903 if (local_err
!= NULL
) {
1911 /* Then try adding all block devices. If one fails, close all and
1914 block_list
= qmp_query_block(NULL
);
1916 for (info
= block_list
; info
; info
= info
->next
) {
1917 if (!info
->value
->has_inserted
) {
1921 qmp_nbd_server_add(info
->value
->device
, true, writable
, &local_err
);
1923 if (local_err
!= NULL
) {
1924 qmp_nbd_server_stop(NULL
);
1929 qapi_free_BlockInfoList(block_list
);
1932 hmp_handle_error(mon
, &local_err
);
1935 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
1937 const char *device
= qdict_get_str(qdict
, "device");
1938 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
1939 Error
*local_err
= NULL
;
1941 qmp_nbd_server_add(device
, true, writable
, &local_err
);
1943 if (local_err
!= NULL
) {
1944 hmp_handle_error(mon
, &local_err
);
1948 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
1952 qmp_nbd_server_stop(&err
);
1953 hmp_handle_error(mon
, &err
);
1956 void hmp_cpu_add(Monitor
*mon
, const QDict
*qdict
)
1961 cpuid
= qdict_get_int(qdict
, "id");
1962 qmp_cpu_add(cpuid
, &err
);
1963 hmp_handle_error(mon
, &err
);
1966 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
1968 const char *args
= qdict_get_str(qdict
, "args");
1972 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
, true);
1974 error_setg(&err
, "Parsing chardev args failed");
1976 qemu_chr_new_from_opts(opts
, NULL
, &err
);
1977 qemu_opts_del(opts
);
1979 hmp_handle_error(mon
, &err
);
1982 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
1984 Error
*local_err
= NULL
;
1986 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
1987 hmp_handle_error(mon
, &local_err
);
1990 void hmp_qemu_io(Monitor
*mon
, const QDict
*qdict
)
1993 BlockBackend
*local_blk
= NULL
;
1994 AioContext
*aio_context
;
1995 const char* device
= qdict_get_str(qdict
, "device");
1996 const char* command
= qdict_get_str(qdict
, "command");
1999 blk
= blk_by_name(device
);
2001 BlockDriverState
*bs
= bdrv_lookup_bs(NULL
, device
, &err
);
2003 blk
= local_blk
= blk_new();
2004 blk_insert_bs(blk
, bs
);
2010 aio_context
= blk_get_aio_context(blk
);
2011 aio_context_acquire(aio_context
);
2013 qemuio_command(blk
, command
);
2015 aio_context_release(aio_context
);
2018 blk_unref(local_blk
);
2019 hmp_handle_error(mon
, &err
);
2022 void hmp_object_del(Monitor
*mon
, const QDict
*qdict
)
2024 const char *id
= qdict_get_str(qdict
, "id");
2027 user_creatable_del(id
, &err
);
2028 hmp_handle_error(mon
, &err
);
2031 void hmp_info_memdev(Monitor
*mon
, const QDict
*qdict
)
2034 MemdevList
*memdev_list
= qmp_query_memdev(&err
);
2035 MemdevList
*m
= memdev_list
;
2042 v
= string_output_visitor_new(false, &str
);
2043 visit_type_uint16List(v
, NULL
, &m
->value
->host_nodes
, NULL
);
2044 monitor_printf(mon
, "memory backend: %d\n", i
);
2045 monitor_printf(mon
, " size: %" PRId64
"\n", m
->value
->size
);
2046 monitor_printf(mon
, " merge: %s\n",
2047 m
->value
->merge
? "true" : "false");
2048 monitor_printf(mon
, " dump: %s\n",
2049 m
->value
->dump
? "true" : "false");
2050 monitor_printf(mon
, " prealloc: %s\n",
2051 m
->value
->prealloc
? "true" : "false");
2052 monitor_printf(mon
, " policy: %s\n",
2053 HostMemPolicy_lookup
[m
->value
->policy
]);
2054 visit_complete(v
, &str
);
2055 monitor_printf(mon
, " host nodes: %s\n", str
);
2063 monitor_printf(mon
, "\n");
2065 qapi_free_MemdevList(memdev_list
);
2068 void hmp_info_memory_devices(Monitor
*mon
, const QDict
*qdict
)
2071 MemoryDeviceInfoList
*info_list
= qmp_query_memory_devices(&err
);
2072 MemoryDeviceInfoList
*info
;
2073 MemoryDeviceInfo
*value
;
2074 PCDIMMDeviceInfo
*di
;
2076 for (info
= info_list
; info
; info
= info
->next
) {
2077 value
= info
->value
;
2080 switch (value
->type
) {
2081 case MEMORY_DEVICE_INFO_KIND_DIMM
:
2082 di
= value
->u
.dimm
.data
;
2084 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
2085 MemoryDeviceInfoKind_lookup
[value
->type
],
2086 di
->id
? di
->id
: "");
2087 monitor_printf(mon
, " addr: 0x%" PRIx64
"\n", di
->addr
);
2088 monitor_printf(mon
, " slot: %" PRId64
"\n", di
->slot
);
2089 monitor_printf(mon
, " node: %" PRId64
"\n", di
->node
);
2090 monitor_printf(mon
, " size: %" PRIu64
"\n", di
->size
);
2091 monitor_printf(mon
, " memdev: %s\n", di
->memdev
);
2092 monitor_printf(mon
, " hotplugged: %s\n",
2093 di
->hotplugged
? "true" : "false");
2094 monitor_printf(mon
, " hotpluggable: %s\n",
2095 di
->hotpluggable
? "true" : "false");
2103 qapi_free_MemoryDeviceInfoList(info_list
);
2106 void hmp_info_iothreads(Monitor
*mon
, const QDict
*qdict
)
2108 IOThreadInfoList
*info_list
= qmp_query_iothreads(NULL
);
2109 IOThreadInfoList
*info
;
2111 for (info
= info_list
; info
; info
= info
->next
) {
2112 monitor_printf(mon
, "%s: thread_id=%" PRId64
"\n",
2113 info
->value
->id
, info
->value
->thread_id
);
2116 qapi_free_IOThreadInfoList(info_list
);
2119 void hmp_qom_list(Monitor
*mon
, const QDict
*qdict
)
2121 const char *path
= qdict_get_try_str(qdict
, "path");
2122 ObjectPropertyInfoList
*list
;
2126 monitor_printf(mon
, "/\n");
2130 list
= qmp_qom_list(path
, &err
);
2132 ObjectPropertyInfoList
*start
= list
;
2133 while (list
!= NULL
) {
2134 ObjectPropertyInfo
*value
= list
->value
;
2136 monitor_printf(mon
, "%s (%s)\n",
2137 value
->name
, value
->type
);
2140 qapi_free_ObjectPropertyInfoList(start
);
2142 hmp_handle_error(mon
, &err
);
2145 void hmp_qom_set(Monitor
*mon
, const QDict
*qdict
)
2147 const char *path
= qdict_get_str(qdict
, "path");
2148 const char *property
= qdict_get_str(qdict
, "property");
2149 const char *value
= qdict_get_str(qdict
, "value");
2151 bool ambiguous
= false;
2154 obj
= object_resolve_path(path
, &ambiguous
);
2156 error_set(&err
, ERROR_CLASS_DEVICE_NOT_FOUND
,
2157 "Device '%s' not found", path
);
2160 monitor_printf(mon
, "Warning: Path '%s' is ambiguous\n", path
);
2162 object_property_parse(obj
, value
, property
, &err
);
2164 hmp_handle_error(mon
, &err
);
2167 void hmp_rocker(Monitor
*mon
, const QDict
*qdict
)
2169 const char *name
= qdict_get_str(qdict
, "name");
2170 RockerSwitch
*rocker
;
2173 rocker
= qmp_query_rocker(name
, &err
);
2175 hmp_handle_error(mon
, &err
);
2179 monitor_printf(mon
, "name: %s\n", rocker
->name
);
2180 monitor_printf(mon
, "id: 0x%" PRIx64
"\n", rocker
->id
);
2181 monitor_printf(mon
, "ports: %d\n", rocker
->ports
);
2183 qapi_free_RockerSwitch(rocker
);
2186 void hmp_rocker_ports(Monitor
*mon
, const QDict
*qdict
)
2188 RockerPortList
*list
, *port
;
2189 const char *name
= qdict_get_str(qdict
, "name");
2192 list
= qmp_query_rocker_ports(name
, &err
);
2194 hmp_handle_error(mon
, &err
);
2198 monitor_printf(mon
, " ena/ speed/ auto\n");
2199 monitor_printf(mon
, " port link duplex neg?\n");
2201 for (port
= list
; port
; port
= port
->next
) {
2202 monitor_printf(mon
, "%10s %-4s %-3s %2s %-3s\n",
2204 port
->value
->enabled
? port
->value
->link_up
?
2205 "up" : "down" : "!ena",
2206 port
->value
->speed
== 10000 ? "10G" : "??",
2207 port
->value
->duplex
? "FD" : "HD",
2208 port
->value
->autoneg
? "Yes" : "No");
2211 qapi_free_RockerPortList(list
);
2214 void hmp_rocker_of_dpa_flows(Monitor
*mon
, const QDict
*qdict
)
2216 RockerOfDpaFlowList
*list
, *info
;
2217 const char *name
= qdict_get_str(qdict
, "name");
2218 uint32_t tbl_id
= qdict_get_try_int(qdict
, "tbl_id", -1);
2221 list
= qmp_query_rocker_of_dpa_flows(name
, tbl_id
!= -1, tbl_id
, &err
);
2223 hmp_handle_error(mon
, &err
);
2227 monitor_printf(mon
, "prio tbl hits key(mask) --> actions\n");
2229 for (info
= list
; info
; info
= info
->next
) {
2230 RockerOfDpaFlow
*flow
= info
->value
;
2231 RockerOfDpaFlowKey
*key
= flow
->key
;
2232 RockerOfDpaFlowMask
*mask
= flow
->mask
;
2233 RockerOfDpaFlowAction
*action
= flow
->action
;
2236 monitor_printf(mon
, "%-4d %-3d %-4" PRIu64
,
2237 key
->priority
, key
->tbl_id
, flow
->hits
);
2239 monitor_printf(mon
, "%-4d %-3d ",
2240 key
->priority
, key
->tbl_id
);
2243 if (key
->has_in_pport
) {
2244 monitor_printf(mon
, " pport %d", key
->in_pport
);
2245 if (mask
->has_in_pport
) {
2246 monitor_printf(mon
, "(0x%x)", mask
->in_pport
);
2250 if (key
->has_vlan_id
) {
2251 monitor_printf(mon
, " vlan %d",
2252 key
->vlan_id
& VLAN_VID_MASK
);
2253 if (mask
->has_vlan_id
) {
2254 monitor_printf(mon
, "(0x%x)", mask
->vlan_id
);
2258 if (key
->has_tunnel_id
) {
2259 monitor_printf(mon
, " tunnel %d", key
->tunnel_id
);
2260 if (mask
->has_tunnel_id
) {
2261 monitor_printf(mon
, "(0x%x)", mask
->tunnel_id
);
2265 if (key
->has_eth_type
) {
2266 switch (key
->eth_type
) {
2268 monitor_printf(mon
, " ARP");
2271 monitor_printf(mon
, " IP");
2274 monitor_printf(mon
, " IPv6");
2277 monitor_printf(mon
, " LACP");
2280 monitor_printf(mon
, " LLDP");
2283 monitor_printf(mon
, " eth type 0x%04x", key
->eth_type
);
2288 if (key
->has_eth_src
) {
2289 if ((strcmp(key
->eth_src
, "01:00:00:00:00:00") == 0) &&
2290 (mask
->has_eth_src
) &&
2291 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2292 monitor_printf(mon
, " src <any mcast/bcast>");
2293 } else if ((strcmp(key
->eth_src
, "00:00:00:00:00:00") == 0) &&
2294 (mask
->has_eth_src
) &&
2295 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2296 monitor_printf(mon
, " src <any ucast>");
2298 monitor_printf(mon
, " src %s", key
->eth_src
);
2299 if (mask
->has_eth_src
) {
2300 monitor_printf(mon
, "(%s)", mask
->eth_src
);
2305 if (key
->has_eth_dst
) {
2306 if ((strcmp(key
->eth_dst
, "01:00:00:00:00:00") == 0) &&
2307 (mask
->has_eth_dst
) &&
2308 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2309 monitor_printf(mon
, " dst <any mcast/bcast>");
2310 } else if ((strcmp(key
->eth_dst
, "00:00:00:00:00:00") == 0) &&
2311 (mask
->has_eth_dst
) &&
2312 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2313 monitor_printf(mon
, " dst <any ucast>");
2315 monitor_printf(mon
, " dst %s", key
->eth_dst
);
2316 if (mask
->has_eth_dst
) {
2317 monitor_printf(mon
, "(%s)", mask
->eth_dst
);
2322 if (key
->has_ip_proto
) {
2323 monitor_printf(mon
, " proto %d", key
->ip_proto
);
2324 if (mask
->has_ip_proto
) {
2325 monitor_printf(mon
, "(0x%x)", mask
->ip_proto
);
2329 if (key
->has_ip_tos
) {
2330 monitor_printf(mon
, " TOS %d", key
->ip_tos
);
2331 if (mask
->has_ip_tos
) {
2332 monitor_printf(mon
, "(0x%x)", mask
->ip_tos
);
2336 if (key
->has_ip_dst
) {
2337 monitor_printf(mon
, " dst %s", key
->ip_dst
);
2340 if (action
->has_goto_tbl
|| action
->has_group_id
||
2341 action
->has_new_vlan_id
) {
2342 monitor_printf(mon
, " -->");
2345 if (action
->has_new_vlan_id
) {
2346 monitor_printf(mon
, " apply new vlan %d",
2347 ntohs(action
->new_vlan_id
));
2350 if (action
->has_group_id
) {
2351 monitor_printf(mon
, " write group 0x%08x", action
->group_id
);
2354 if (action
->has_goto_tbl
) {
2355 monitor_printf(mon
, " goto tbl %d", action
->goto_tbl
);
2358 monitor_printf(mon
, "\n");
2361 qapi_free_RockerOfDpaFlowList(list
);
2364 void hmp_rocker_of_dpa_groups(Monitor
*mon
, const QDict
*qdict
)
2366 RockerOfDpaGroupList
*list
, *g
;
2367 const char *name
= qdict_get_str(qdict
, "name");
2368 uint8_t type
= qdict_get_try_int(qdict
, "type", 9);
2372 list
= qmp_query_rocker_of_dpa_groups(name
, type
!= 9, type
, &err
);
2374 hmp_handle_error(mon
, &err
);
2378 monitor_printf(mon
, "id (decode) --> buckets\n");
2380 for (g
= list
; g
; g
= g
->next
) {
2381 RockerOfDpaGroup
*group
= g
->value
;
2383 monitor_printf(mon
, "0x%08x", group
->id
);
2385 monitor_printf(mon
, " (type %s", group
->type
== 0 ? "L2 interface" :
2386 group
->type
== 1 ? "L2 rewrite" :
2387 group
->type
== 2 ? "L3 unicast" :
2388 group
->type
== 3 ? "L2 multicast" :
2389 group
->type
== 4 ? "L2 flood" :
2390 group
->type
== 5 ? "L3 interface" :
2391 group
->type
== 6 ? "L3 multicast" :
2392 group
->type
== 7 ? "L3 ECMP" :
2393 group
->type
== 8 ? "L2 overlay" :
2396 if (group
->has_vlan_id
) {
2397 monitor_printf(mon
, " vlan %d", group
->vlan_id
);
2400 if (group
->has_pport
) {
2401 monitor_printf(mon
, " pport %d", group
->pport
);
2404 if (group
->has_index
) {
2405 monitor_printf(mon
, " index %d", group
->index
);
2408 monitor_printf(mon
, ") -->");
2410 if (group
->has_set_vlan_id
&& group
->set_vlan_id
) {
2412 monitor_printf(mon
, " set vlan %d",
2413 group
->set_vlan_id
& VLAN_VID_MASK
);
2416 if (group
->has_set_eth_src
) {
2419 monitor_printf(mon
, " set");
2421 monitor_printf(mon
, " src %s", group
->set_eth_src
);
2424 if (group
->has_set_eth_dst
) {
2427 monitor_printf(mon
, " set");
2429 monitor_printf(mon
, " dst %s", group
->set_eth_dst
);
2434 if (group
->has_ttl_check
&& group
->ttl_check
) {
2435 monitor_printf(mon
, " check TTL");
2438 if (group
->has_group_id
&& group
->group_id
) {
2439 monitor_printf(mon
, " group id 0x%08x", group
->group_id
);
2442 if (group
->has_pop_vlan
&& group
->pop_vlan
) {
2443 monitor_printf(mon
, " pop vlan");
2446 if (group
->has_out_pport
) {
2447 monitor_printf(mon
, " out pport %d", group
->out_pport
);
2450 if (group
->has_group_ids
) {
2451 struct uint32List
*id
;
2453 monitor_printf(mon
, " groups [");
2454 for (id
= group
->group_ids
; id
; id
= id
->next
) {
2455 monitor_printf(mon
, "0x%08x", id
->value
);
2457 monitor_printf(mon
, ",");
2460 monitor_printf(mon
, "]");
2463 monitor_printf(mon
, "\n");
2466 qapi_free_RockerOfDpaGroupList(list
);
2469 void hmp_info_dump(Monitor
*mon
, const QDict
*qdict
)
2471 DumpQueryResult
*result
= qmp_query_dump(NULL
);
2473 assert(result
&& result
->status
< DUMP_STATUS__MAX
);
2474 monitor_printf(mon
, "Status: %s\n", DumpStatus_lookup
[result
->status
]);
2476 if (result
->status
== DUMP_STATUS_ACTIVE
) {
2478 assert(result
->total
!= 0);
2479 percent
= 100.0 * result
->completed
/ result
->total
;
2480 monitor_printf(mon
, "Finished: %.2f %%\n", percent
);
2483 qapi_free_DumpQueryResult(result
);
2486 void hmp_hotpluggable_cpus(Monitor
*mon
, const QDict
*qdict
)
2489 HotpluggableCPUList
*l
= qmp_query_hotpluggable_cpus(&err
);
2490 HotpluggableCPUList
*saved
= l
;
2491 CpuInstanceProperties
*c
;
2494 hmp_handle_error(mon
, &err
);
2498 monitor_printf(mon
, "Hotpluggable CPUs:\n");
2500 monitor_printf(mon
, " type: \"%s\"\n", l
->value
->type
);
2501 monitor_printf(mon
, " vcpus_count: \"%" PRIu64
"\"\n",
2502 l
->value
->vcpus_count
);
2503 if (l
->value
->has_qom_path
) {
2504 monitor_printf(mon
, " qom_path: \"%s\"\n", l
->value
->qom_path
);
2507 c
= l
->value
->props
;
2508 monitor_printf(mon
, " CPUInstance Properties:\n");
2509 if (c
->has_node_id
) {
2510 monitor_printf(mon
, " node-id: \"%" PRIu64
"\"\n", c
->node_id
);
2512 if (c
->has_socket_id
) {
2513 monitor_printf(mon
, " socket-id: \"%" PRIu64
"\"\n", c
->socket_id
);
2515 if (c
->has_core_id
) {
2516 monitor_printf(mon
, " core-id: \"%" PRIu64
"\"\n", c
->core_id
);
2518 if (c
->has_thread_id
) {
2519 monitor_printf(mon
, " thread-id: \"%" PRIu64
"\"\n", c
->thread_id
);
2525 qapi_free_HotpluggableCPUList(saved
);