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/config-file.h"
23 #include "qemu/option.h"
24 #include "qemu/timer.h"
25 #include "qmp-commands.h"
26 #include "qemu/sockets.h"
27 #include "monitor/monitor.h"
28 #include "monitor/qdev.h"
29 #include "qapi/opts-visitor.h"
30 #include "qapi/qmp/qerror.h"
31 #include "qapi/string-output-visitor.h"
32 #include "qapi/util.h"
33 #include "qapi-visit.h"
34 #include "qom/object_interfaces.h"
35 #include "ui/console.h"
36 #include "block/qapi.h"
38 #include "qemu/cutils.h"
39 #include "qemu/error-report.h"
40 #include "hw/intc/intc.h"
43 #include <spice/enums.h>
46 static void hmp_handle_error(Monitor
*mon
, Error
**errp
)
50 error_report_err(*errp
);
54 void hmp_info_name(Monitor
*mon
, const QDict
*qdict
)
58 info
= qmp_query_name(NULL
);
60 monitor_printf(mon
, "%s\n", info
->name
);
62 qapi_free_NameInfo(info
);
65 void hmp_info_version(Monitor
*mon
, const QDict
*qdict
)
69 info
= qmp_query_version(NULL
);
71 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
72 info
->qemu
->major
, info
->qemu
->minor
, info
->qemu
->micro
,
75 qapi_free_VersionInfo(info
);
78 void hmp_info_kvm(Monitor
*mon
, const QDict
*qdict
)
82 info
= qmp_query_kvm(NULL
);
83 monitor_printf(mon
, "kvm support: ");
85 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
87 monitor_printf(mon
, "not compiled\n");
90 qapi_free_KvmInfo(info
);
93 void hmp_info_status(Monitor
*mon
, const QDict
*qdict
)
97 info
= qmp_query_status(NULL
);
99 monitor_printf(mon
, "VM status: %s%s",
100 info
->running
? "running" : "paused",
101 info
->singlestep
? " (single step mode)" : "");
103 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
104 monitor_printf(mon
, " (%s)", RunState_lookup
[info
->status
]);
107 monitor_printf(mon
, "\n");
109 qapi_free_StatusInfo(info
);
112 void hmp_info_uuid(Monitor
*mon
, const QDict
*qdict
)
116 info
= qmp_query_uuid(NULL
);
117 monitor_printf(mon
, "%s\n", info
->UUID
);
118 qapi_free_UuidInfo(info
);
121 void hmp_info_chardev(Monitor
*mon
, const QDict
*qdict
)
123 ChardevInfoList
*char_info
, *info
;
125 char_info
= qmp_query_chardev(NULL
);
126 for (info
= char_info
; info
; info
= info
->next
) {
127 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
128 info
->value
->filename
);
131 qapi_free_ChardevInfoList(char_info
);
134 void hmp_info_mice(Monitor
*mon
, const QDict
*qdict
)
136 MouseInfoList
*mice_list
, *mouse
;
138 mice_list
= qmp_query_mice(NULL
);
140 monitor_printf(mon
, "No mouse devices connected\n");
144 for (mouse
= mice_list
; mouse
; mouse
= mouse
->next
) {
145 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s%s\n",
146 mouse
->value
->current
? '*' : ' ',
147 mouse
->value
->index
, mouse
->value
->name
,
148 mouse
->value
->absolute
? " (absolute)" : "");
151 qapi_free_MouseInfoList(mice_list
);
154 void hmp_info_migrate(Monitor
*mon
, const QDict
*qdict
)
157 MigrationCapabilityStatusList
*caps
, *cap
;
159 info
= qmp_query_migrate(NULL
);
160 caps
= qmp_query_migrate_capabilities(NULL
);
162 /* do not display parameters during setup */
163 if (info
->has_status
&& caps
) {
164 monitor_printf(mon
, "capabilities: ");
165 for (cap
= caps
; cap
; cap
= cap
->next
) {
166 monitor_printf(mon
, "%s: %s ",
167 MigrationCapability_lookup
[cap
->value
->capability
],
168 cap
->value
->state
? "on" : "off");
170 monitor_printf(mon
, "\n");
173 if (info
->has_status
) {
174 monitor_printf(mon
, "Migration status: %s",
175 MigrationStatus_lookup
[info
->status
]);
176 if (info
->status
== MIGRATION_STATUS_FAILED
&&
177 info
->has_error_desc
) {
178 monitor_printf(mon
, " (%s)\n", info
->error_desc
);
180 monitor_printf(mon
, "\n");
183 monitor_printf(mon
, "total time: %" PRIu64
" milliseconds\n",
185 if (info
->has_expected_downtime
) {
186 monitor_printf(mon
, "expected downtime: %" PRIu64
" milliseconds\n",
187 info
->expected_downtime
);
189 if (info
->has_downtime
) {
190 monitor_printf(mon
, "downtime: %" PRIu64
" milliseconds\n",
193 if (info
->has_setup_time
) {
194 monitor_printf(mon
, "setup: %" PRIu64
" milliseconds\n",
200 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
201 info
->ram
->transferred
>> 10);
202 monitor_printf(mon
, "throughput: %0.2f mbps\n",
204 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
205 info
->ram
->remaining
>> 10);
206 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
207 info
->ram
->total
>> 10);
208 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
209 info
->ram
->duplicate
);
210 monitor_printf(mon
, "skipped: %" PRIu64
" pages\n",
212 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
214 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
215 info
->ram
->normal_bytes
>> 10);
216 monitor_printf(mon
, "dirty sync count: %" PRIu64
"\n",
217 info
->ram
->dirty_sync_count
);
218 monitor_printf(mon
, "page size: %" PRIu64
" kbytes\n",
219 info
->ram
->page_size
>> 10);
221 if (info
->ram
->dirty_pages_rate
) {
222 monitor_printf(mon
, "dirty pages rate: %" PRIu64
" pages\n",
223 info
->ram
->dirty_pages_rate
);
225 if (info
->ram
->postcopy_requests
) {
226 monitor_printf(mon
, "postcopy request count: %" PRIu64
"\n",
227 info
->ram
->postcopy_requests
);
231 if (info
->has_disk
) {
232 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
233 info
->disk
->transferred
>> 10);
234 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
235 info
->disk
->remaining
>> 10);
236 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
237 info
->disk
->total
>> 10);
240 if (info
->has_xbzrle_cache
) {
241 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
242 info
->xbzrle_cache
->cache_size
);
243 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
244 info
->xbzrle_cache
->bytes
>> 10);
245 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
246 info
->xbzrle_cache
->pages
);
247 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
"\n",
248 info
->xbzrle_cache
->cache_miss
);
249 monitor_printf(mon
, "xbzrle cache miss rate: %0.2f\n",
250 info
->xbzrle_cache
->cache_miss_rate
);
251 monitor_printf(mon
, "xbzrle overflow : %" PRIu64
"\n",
252 info
->xbzrle_cache
->overflow
);
255 if (info
->has_cpu_throttle_percentage
) {
256 monitor_printf(mon
, "cpu throttle percentage: %" PRIu64
"\n",
257 info
->cpu_throttle_percentage
);
260 qapi_free_MigrationInfo(info
);
261 qapi_free_MigrationCapabilityStatusList(caps
);
264 void hmp_info_migrate_capabilities(Monitor
*mon
, const QDict
*qdict
)
266 MigrationCapabilityStatusList
*caps
, *cap
;
268 caps
= qmp_query_migrate_capabilities(NULL
);
271 for (cap
= caps
; cap
; cap
= cap
->next
) {
272 monitor_printf(mon
, "%s: %s\n",
273 MigrationCapability_lookup
[cap
->value
->capability
],
274 cap
->value
->state
? "on" : "off");
278 qapi_free_MigrationCapabilityStatusList(caps
);
281 void hmp_info_migrate_parameters(Monitor
*mon
, const QDict
*qdict
)
283 MigrationParameters
*params
;
285 params
= qmp_query_migrate_parameters(NULL
);
288 assert(params
->has_compress_level
);
289 monitor_printf(mon
, "%s: %" PRId64
"\n",
290 MigrationParameter_lookup
[MIGRATION_PARAMETER_COMPRESS_LEVEL
],
291 params
->compress_level
);
292 assert(params
->has_compress_threads
);
293 monitor_printf(mon
, "%s: %" PRId64
"\n",
294 MigrationParameter_lookup
[MIGRATION_PARAMETER_COMPRESS_THREADS
],
295 params
->compress_threads
);
296 assert(params
->has_decompress_threads
);
297 monitor_printf(mon
, "%s: %" PRId64
"\n",
298 MigrationParameter_lookup
[MIGRATION_PARAMETER_DECOMPRESS_THREADS
],
299 params
->decompress_threads
);
300 assert(params
->has_cpu_throttle_initial
);
301 monitor_printf(mon
, "%s: %" PRId64
"\n",
302 MigrationParameter_lookup
[MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
],
303 params
->cpu_throttle_initial
);
304 assert(params
->has_cpu_throttle_increment
);
305 monitor_printf(mon
, "%s: %" PRId64
"\n",
306 MigrationParameter_lookup
[MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
],
307 params
->cpu_throttle_increment
);
308 monitor_printf(mon
, "%s: '%s'\n",
309 MigrationParameter_lookup
[MIGRATION_PARAMETER_TLS_CREDS
],
310 params
->has_tls_creds
? params
->tls_creds
: "");
311 monitor_printf(mon
, "%s: '%s'\n",
312 MigrationParameter_lookup
[MIGRATION_PARAMETER_TLS_HOSTNAME
],
313 params
->has_tls_hostname
? params
->tls_hostname
: "");
314 assert(params
->has_max_bandwidth
);
315 monitor_printf(mon
, "%s: %" PRId64
" bytes/second\n",
316 MigrationParameter_lookup
[MIGRATION_PARAMETER_MAX_BANDWIDTH
],
317 params
->max_bandwidth
);
318 assert(params
->has_downtime_limit
);
319 monitor_printf(mon
, "%s: %" PRId64
" milliseconds\n",
320 MigrationParameter_lookup
[MIGRATION_PARAMETER_DOWNTIME_LIMIT
],
321 params
->downtime_limit
);
322 assert(params
->has_x_checkpoint_delay
);
323 monitor_printf(mon
, "%s: %" PRId64
"\n",
324 MigrationParameter_lookup
[MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
],
325 params
->x_checkpoint_delay
);
328 qapi_free_MigrationParameters(params
);
331 void hmp_info_migrate_cache_size(Monitor
*mon
, const QDict
*qdict
)
333 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
334 qmp_query_migrate_cache_size(NULL
) >> 10);
337 void hmp_info_cpus(Monitor
*mon
, const QDict
*qdict
)
339 CpuInfoList
*cpu_list
, *cpu
;
341 cpu_list
= qmp_query_cpus(NULL
);
343 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
346 if (cpu
->value
->CPU
== monitor_get_cpu_index()) {
350 monitor_printf(mon
, "%c CPU #%" PRId64
":", active
, cpu
->value
->CPU
);
352 switch (cpu
->value
->arch
) {
353 case CPU_INFO_ARCH_X86
:
354 monitor_printf(mon
, " pc=0x%016" PRIx64
, cpu
->value
->u
.x86
.pc
);
356 case CPU_INFO_ARCH_PPC
:
357 monitor_printf(mon
, " nip=0x%016" PRIx64
, cpu
->value
->u
.ppc
.nip
);
359 case CPU_INFO_ARCH_SPARC
:
360 monitor_printf(mon
, " pc=0x%016" PRIx64
,
361 cpu
->value
->u
.q_sparc
.pc
);
362 monitor_printf(mon
, " npc=0x%016" PRIx64
,
363 cpu
->value
->u
.q_sparc
.npc
);
365 case CPU_INFO_ARCH_MIPS
:
366 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->u
.q_mips
.PC
);
368 case CPU_INFO_ARCH_TRICORE
:
369 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->u
.tricore
.PC
);
375 if (cpu
->value
->halted
) {
376 monitor_printf(mon
, " (halted)");
379 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
382 qapi_free_CpuInfoList(cpu_list
);
385 static void print_block_info(Monitor
*mon
, BlockInfo
*info
,
386 BlockDeviceInfo
*inserted
, bool verbose
)
388 ImageInfo
*image_info
;
390 assert(!info
|| !info
->has_inserted
|| info
->inserted
== inserted
);
393 monitor_printf(mon
, "%s", info
->device
);
394 if (inserted
&& inserted
->has_node_name
) {
395 monitor_printf(mon
, " (%s)", inserted
->node_name
);
399 monitor_printf(mon
, "%s",
400 inserted
->has_node_name
401 ? inserted
->node_name
406 monitor_printf(mon
, ": %s (%s%s%s)\n",
409 inserted
->ro
? ", read-only" : "",
410 inserted
->encrypted
? ", encrypted" : "");
412 monitor_printf(mon
, ": [not inserted]\n");
416 if (info
->has_io_status
&& info
->io_status
!= BLOCK_DEVICE_IO_STATUS_OK
) {
417 monitor_printf(mon
, " I/O status: %s\n",
418 BlockDeviceIoStatus_lookup
[info
->io_status
]);
421 if (info
->removable
) {
422 monitor_printf(mon
, " Removable device: %slocked, tray %s\n",
423 info
->locked
? "" : "not ",
424 info
->tray_open
? "open" : "closed");
433 monitor_printf(mon
, " Cache mode: %s%s%s\n",
434 inserted
->cache
->writeback
? "writeback" : "writethrough",
435 inserted
->cache
->direct
? ", direct" : "",
436 inserted
->cache
->no_flush
? ", ignore flushes" : "");
438 if (inserted
->has_backing_file
) {
441 "(chain depth: %" PRId64
")\n",
442 inserted
->backing_file
,
443 inserted
->backing_file_depth
);
446 if (inserted
->detect_zeroes
!= BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF
) {
447 monitor_printf(mon
, " Detect zeroes: %s\n",
448 BlockdevDetectZeroesOptions_lookup
[inserted
->detect_zeroes
]);
451 if (inserted
->bps
|| inserted
->bps_rd
|| inserted
->bps_wr
||
452 inserted
->iops
|| inserted
->iops_rd
|| inserted
->iops_wr
)
454 monitor_printf(mon
, " I/O throttling: bps=%" PRId64
455 " bps_rd=%" PRId64
" bps_wr=%" PRId64
457 " bps_rd_max=%" PRId64
458 " bps_wr_max=%" PRId64
459 " iops=%" PRId64
" iops_rd=%" PRId64
462 " iops_rd_max=%" PRId64
463 " iops_wr_max=%" PRId64
464 " iops_size=%" PRId64
470 inserted
->bps_rd_max
,
471 inserted
->bps_wr_max
,
476 inserted
->iops_rd_max
,
477 inserted
->iops_wr_max
,
483 monitor_printf(mon
, "\nImages:\n");
484 image_info
= inserted
->image
;
486 bdrv_image_info_dump((fprintf_function
)monitor_printf
,
488 if (image_info
->has_backing_image
) {
489 image_info
= image_info
->backing_image
;
497 void hmp_info_block(Monitor
*mon
, const QDict
*qdict
)
499 BlockInfoList
*block_list
, *info
;
500 BlockDeviceInfoList
*blockdev_list
, *blockdev
;
501 const char *device
= qdict_get_try_str(qdict
, "device");
502 bool verbose
= qdict_get_try_bool(qdict
, "verbose", false);
503 bool nodes
= qdict_get_try_bool(qdict
, "nodes", false);
504 bool printed
= false;
506 /* Print BlockBackend information */
508 block_list
= qmp_query_block(NULL
);
513 for (info
= block_list
; info
; info
= info
->next
) {
514 if (device
&& strcmp(device
, info
->value
->device
)) {
518 if (info
!= block_list
) {
519 monitor_printf(mon
, "\n");
522 print_block_info(mon
, info
->value
, info
->value
->has_inserted
523 ? info
->value
->inserted
: NULL
,
528 qapi_free_BlockInfoList(block_list
);
530 if ((!device
&& !nodes
) || printed
) {
534 /* Print node information */
535 blockdev_list
= qmp_query_named_block_nodes(NULL
);
536 for (blockdev
= blockdev_list
; blockdev
; blockdev
= blockdev
->next
) {
537 assert(blockdev
->value
->has_node_name
);
538 if (device
&& strcmp(device
, blockdev
->value
->node_name
)) {
542 if (blockdev
!= blockdev_list
) {
543 monitor_printf(mon
, "\n");
546 print_block_info(mon
, NULL
, blockdev
->value
, verbose
);
548 qapi_free_BlockDeviceInfoList(blockdev_list
);
551 void hmp_info_blockstats(Monitor
*mon
, const QDict
*qdict
)
553 BlockStatsList
*stats_list
, *stats
;
555 stats_list
= qmp_query_blockstats(false, false, NULL
);
557 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
558 if (!stats
->value
->has_device
) {
562 monitor_printf(mon
, "%s:", stats
->value
->device
);
563 monitor_printf(mon
, " rd_bytes=%" PRId64
565 " rd_operations=%" PRId64
566 " wr_operations=%" PRId64
567 " flush_operations=%" PRId64
568 " wr_total_time_ns=%" PRId64
569 " rd_total_time_ns=%" PRId64
570 " flush_total_time_ns=%" PRId64
571 " rd_merged=%" PRId64
572 " wr_merged=%" PRId64
573 " idle_time_ns=%" PRId64
575 stats
->value
->stats
->rd_bytes
,
576 stats
->value
->stats
->wr_bytes
,
577 stats
->value
->stats
->rd_operations
,
578 stats
->value
->stats
->wr_operations
,
579 stats
->value
->stats
->flush_operations
,
580 stats
->value
->stats
->wr_total_time_ns
,
581 stats
->value
->stats
->rd_total_time_ns
,
582 stats
->value
->stats
->flush_total_time_ns
,
583 stats
->value
->stats
->rd_merged
,
584 stats
->value
->stats
->wr_merged
,
585 stats
->value
->stats
->idle_time_ns
);
588 qapi_free_BlockStatsList(stats_list
);
591 void hmp_info_vnc(Monitor
*mon
, const QDict
*qdict
)
595 VncClientInfoList
*client
;
597 info
= qmp_query_vnc(&err
);
599 error_report_err(err
);
603 if (!info
->enabled
) {
604 monitor_printf(mon
, "Server: disabled\n");
608 monitor_printf(mon
, "Server:\n");
609 if (info
->has_host
&& info
->has_service
) {
610 monitor_printf(mon
, " address: %s:%s\n", info
->host
, info
->service
);
612 if (info
->has_auth
) {
613 monitor_printf(mon
, " auth: %s\n", info
->auth
);
616 if (!info
->has_clients
|| info
->clients
== NULL
) {
617 monitor_printf(mon
, "Client: none\n");
619 for (client
= info
->clients
; client
; client
= client
->next
) {
620 monitor_printf(mon
, "Client:\n");
621 monitor_printf(mon
, " address: %s:%s\n",
623 client
->value
->service
);
624 monitor_printf(mon
, " x509_dname: %s\n",
625 client
->value
->x509_dname
?
626 client
->value
->x509_dname
: "none");
627 monitor_printf(mon
, " username: %s\n",
628 client
->value
->has_sasl_username
?
629 client
->value
->sasl_username
: "none");
634 qapi_free_VncInfo(info
);
638 void hmp_info_spice(Monitor
*mon
, const QDict
*qdict
)
640 SpiceChannelList
*chan
;
642 const char *channel_name
;
643 const char * const channel_names
[] = {
644 [SPICE_CHANNEL_MAIN
] = "main",
645 [SPICE_CHANNEL_DISPLAY
] = "display",
646 [SPICE_CHANNEL_INPUTS
] = "inputs",
647 [SPICE_CHANNEL_CURSOR
] = "cursor",
648 [SPICE_CHANNEL_PLAYBACK
] = "playback",
649 [SPICE_CHANNEL_RECORD
] = "record",
650 [SPICE_CHANNEL_TUNNEL
] = "tunnel",
651 [SPICE_CHANNEL_SMARTCARD
] = "smartcard",
652 [SPICE_CHANNEL_USBREDIR
] = "usbredir",
653 [SPICE_CHANNEL_PORT
] = "port",
655 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
656 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
657 * as quick fix for build failures with older versions. */
658 [SPICE_CHANNEL_WEBDAV
] = "webdav",
662 info
= qmp_query_spice(NULL
);
664 if (!info
->enabled
) {
665 monitor_printf(mon
, "Server: disabled\n");
669 monitor_printf(mon
, "Server:\n");
670 if (info
->has_port
) {
671 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
672 info
->host
, info
->port
);
674 if (info
->has_tls_port
) {
675 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
676 info
->host
, info
->tls_port
);
678 monitor_printf(mon
, " migrated: %s\n",
679 info
->migrated
? "true" : "false");
680 monitor_printf(mon
, " auth: %s\n", info
->auth
);
681 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
682 monitor_printf(mon
, " mouse-mode: %s\n",
683 SpiceQueryMouseMode_lookup
[info
->mouse_mode
]);
685 if (!info
->has_channels
|| info
->channels
== NULL
) {
686 monitor_printf(mon
, "Channels: none\n");
688 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
689 monitor_printf(mon
, "Channel:\n");
690 monitor_printf(mon
, " address: %s:%s%s\n",
691 chan
->value
->host
, chan
->value
->port
,
692 chan
->value
->tls
? " [tls]" : "");
693 monitor_printf(mon
, " session: %" PRId64
"\n",
694 chan
->value
->connection_id
);
695 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
696 chan
->value
->channel_type
, chan
->value
->channel_id
);
698 channel_name
= "unknown";
699 if (chan
->value
->channel_type
> 0 &&
700 chan
->value
->channel_type
< ARRAY_SIZE(channel_names
) &&
701 channel_names
[chan
->value
->channel_type
]) {
702 channel_name
= channel_names
[chan
->value
->channel_type
];
705 monitor_printf(mon
, " channel name: %s\n", channel_name
);
710 qapi_free_SpiceInfo(info
);
714 void hmp_info_balloon(Monitor
*mon
, const QDict
*qdict
)
719 info
= qmp_query_balloon(&err
);
721 error_report_err(err
);
725 monitor_printf(mon
, "balloon: actual=%" PRId64
"\n", info
->actual
>> 20);
727 qapi_free_BalloonInfo(info
);
730 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
732 PciMemoryRegionList
*region
;
734 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
735 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
736 dev
->slot
, dev
->function
);
737 monitor_printf(mon
, " ");
739 if (dev
->class_info
->has_desc
) {
740 monitor_printf(mon
, "%s", dev
->class_info
->desc
);
742 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
->q_class
);
745 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
746 dev
->id
->vendor
, dev
->id
->device
);
749 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
752 if (dev
->has_pci_bridge
) {
753 monitor_printf(mon
, " BUS %" PRId64
".\n",
754 dev
->pci_bridge
->bus
->number
);
755 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
756 dev
->pci_bridge
->bus
->secondary
);
757 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
758 dev
->pci_bridge
->bus
->subordinate
);
760 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
761 dev
->pci_bridge
->bus
->io_range
->base
,
762 dev
->pci_bridge
->bus
->io_range
->limit
);
765 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
766 dev
->pci_bridge
->bus
->memory_range
->base
,
767 dev
->pci_bridge
->bus
->memory_range
->limit
);
769 monitor_printf(mon
, " prefetchable memory range "
770 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
771 dev
->pci_bridge
->bus
->prefetchable_range
->base
,
772 dev
->pci_bridge
->bus
->prefetchable_range
->limit
);
775 for (region
= dev
->regions
; region
; region
= region
->next
) {
778 addr
= region
->value
->address
;
779 size
= region
->value
->size
;
781 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
783 if (!strcmp(region
->value
->type
, "io")) {
784 monitor_printf(mon
, "I/O at 0x%04" PRIx64
785 " [0x%04" PRIx64
"].\n",
786 addr
, addr
+ size
- 1);
788 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
789 " [0x%08" PRIx64
"].\n",
790 region
->value
->mem_type_64
? 64 : 32,
791 region
->value
->prefetch
? " prefetchable" : "",
792 addr
, addr
+ size
- 1);
796 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
798 if (dev
->has_pci_bridge
) {
799 if (dev
->pci_bridge
->has_devices
) {
800 PciDeviceInfoList
*cdev
;
801 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
802 hmp_info_pci_device(mon
, cdev
->value
);
808 static int hmp_info_irq_foreach(Object
*obj
, void *opaque
)
810 InterruptStatsProvider
*intc
;
811 InterruptStatsProviderClass
*k
;
812 Monitor
*mon
= opaque
;
814 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
815 intc
= INTERRUPT_STATS_PROVIDER(obj
);
816 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
817 uint64_t *irq_counts
;
818 unsigned int nb_irqs
, i
;
819 if (k
->get_statistics
&&
820 k
->get_statistics(intc
, &irq_counts
, &nb_irqs
)) {
822 monitor_printf(mon
, "IRQ statistics for %s:\n",
823 object_get_typename(obj
));
824 for (i
= 0; i
< nb_irqs
; i
++) {
825 if (irq_counts
[i
] > 0) {
826 monitor_printf(mon
, "%2d: %" PRId64
"\n", i
,
832 monitor_printf(mon
, "IRQ statistics not available for %s.\n",
833 object_get_typename(obj
));
840 void hmp_info_irq(Monitor
*mon
, const QDict
*qdict
)
842 object_child_foreach_recursive(object_get_root(),
843 hmp_info_irq_foreach
, mon
);
846 static int hmp_info_pic_foreach(Object
*obj
, void *opaque
)
848 InterruptStatsProvider
*intc
;
849 InterruptStatsProviderClass
*k
;
850 Monitor
*mon
= opaque
;
852 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
853 intc
= INTERRUPT_STATS_PROVIDER(obj
);
854 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
856 k
->print_info(intc
, mon
);
858 monitor_printf(mon
, "Interrupt controller information not available for %s.\n",
859 object_get_typename(obj
));
866 void hmp_info_pic(Monitor
*mon
, const QDict
*qdict
)
868 object_child_foreach_recursive(object_get_root(),
869 hmp_info_pic_foreach
, mon
);
872 void hmp_info_pci(Monitor
*mon
, const QDict
*qdict
)
874 PciInfoList
*info_list
, *info
;
877 info_list
= qmp_query_pci(&err
);
879 monitor_printf(mon
, "PCI devices not supported\n");
884 for (info
= info_list
; info
; info
= info
->next
) {
885 PciDeviceInfoList
*dev
;
887 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
888 hmp_info_pci_device(mon
, dev
->value
);
892 qapi_free_PciInfoList(info_list
);
895 void hmp_info_block_jobs(Monitor
*mon
, const QDict
*qdict
)
897 BlockJobInfoList
*list
;
900 list
= qmp_query_block_jobs(&err
);
904 monitor_printf(mon
, "No active jobs\n");
909 if (strcmp(list
->value
->type
, "stream") == 0) {
910 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
911 " of %" PRId64
" bytes, speed limit %" PRId64
918 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
919 " of %" PRId64
" bytes, speed limit %" PRId64
930 qapi_free_BlockJobInfoList(list
);
933 void hmp_info_tpm(Monitor
*mon
, const QDict
*qdict
)
935 TPMInfoList
*info_list
, *info
;
938 TPMPassthroughOptions
*tpo
;
940 info_list
= qmp_query_tpm(&err
);
942 monitor_printf(mon
, "TPM device not supported\n");
948 monitor_printf(mon
, "TPM device:\n");
951 for (info
= info_list
; info
; info
= info
->next
) {
952 TPMInfo
*ti
= info
->value
;
953 monitor_printf(mon
, " tpm%d: model=%s\n",
954 c
, TpmModel_lookup
[ti
->model
]);
956 monitor_printf(mon
, " \\ %s: type=%s",
957 ti
->id
, TpmTypeOptionsKind_lookup
[ti
->options
->type
]);
959 switch (ti
->options
->type
) {
960 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH
:
961 tpo
= ti
->options
->u
.passthrough
.data
;
962 monitor_printf(mon
, "%s%s%s%s",
963 tpo
->has_path
? ",path=" : "",
964 tpo
->has_path
? tpo
->path
: "",
965 tpo
->has_cancel_path
? ",cancel-path=" : "",
966 tpo
->has_cancel_path
? tpo
->cancel_path
: "");
968 case TPM_TYPE_OPTIONS_KIND__MAX
:
971 monitor_printf(mon
, "\n");
974 qapi_free_TPMInfoList(info_list
);
977 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
979 monitor_suspend(mon
);
983 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
988 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
990 qmp_system_reset(NULL
);
993 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
995 qmp_system_powerdown(NULL
);
998 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
1002 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1003 use it are converted to the QAPI */
1004 cpu_index
= qdict_get_int(qdict
, "index");
1005 if (monitor_set_cpu(cpu_index
) < 0) {
1006 monitor_printf(mon
, "invalid CPU index\n");
1010 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
1012 uint32_t size
= qdict_get_int(qdict
, "size");
1013 const char *filename
= qdict_get_str(qdict
, "filename");
1014 uint64_t addr
= qdict_get_int(qdict
, "val");
1016 int cpu_index
= monitor_get_cpu_index();
1018 if (cpu_index
< 0) {
1019 monitor_printf(mon
, "No CPU available\n");
1023 qmp_memsave(addr
, size
, filename
, true, cpu_index
, &err
);
1024 hmp_handle_error(mon
, &err
);
1027 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
1029 uint32_t size
= qdict_get_int(qdict
, "size");
1030 const char *filename
= qdict_get_str(qdict
, "filename");
1031 uint64_t addr
= qdict_get_int(qdict
, "val");
1034 qmp_pmemsave(addr
, size
, filename
, &err
);
1035 hmp_handle_error(mon
, &err
);
1038 void hmp_ringbuf_write(Monitor
*mon
, const QDict
*qdict
)
1040 const char *chardev
= qdict_get_str(qdict
, "device");
1041 const char *data
= qdict_get_str(qdict
, "data");
1044 qmp_ringbuf_write(chardev
, data
, false, 0, &err
);
1046 hmp_handle_error(mon
, &err
);
1049 void hmp_ringbuf_read(Monitor
*mon
, const QDict
*qdict
)
1051 uint32_t size
= qdict_get_int(qdict
, "size");
1052 const char *chardev
= qdict_get_str(qdict
, "device");
1057 data
= qmp_ringbuf_read(chardev
, size
, false, 0, &err
);
1059 error_report_err(err
);
1063 for (i
= 0; data
[i
]; i
++) {
1064 unsigned char ch
= data
[i
];
1067 monitor_printf(mon
, "\\\\");
1068 } else if ((ch
< 0x20 && ch
!= '\n' && ch
!= '\t') || ch
== 0x7F) {
1069 monitor_printf(mon
, "\\u%04X", ch
);
1071 monitor_printf(mon
, "%c", ch
);
1075 monitor_printf(mon
, "\n");
1079 static void hmp_cont_cb(void *opaque
, int err
)
1086 static bool key_is_missing(const BlockInfo
*bdev
)
1088 return (bdev
->inserted
&& bdev
->inserted
->encryption_key_missing
);
1091 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
1093 BlockInfoList
*bdev_list
, *bdev
;
1096 bdev_list
= qmp_query_block(NULL
);
1097 for (bdev
= bdev_list
; bdev
; bdev
= bdev
->next
) {
1098 if (key_is_missing(bdev
->value
)) {
1099 monitor_read_block_device_key(mon
, bdev
->value
->device
,
1106 hmp_handle_error(mon
, &err
);
1109 qapi_free_BlockInfoList(bdev_list
);
1112 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
1114 qmp_system_wakeup(NULL
);
1117 void hmp_nmi(Monitor
*mon
, const QDict
*qdict
)
1121 qmp_inject_nmi(&err
);
1122 hmp_handle_error(mon
, &err
);
1125 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
1127 const char *name
= qdict_get_str(qdict
, "name");
1128 bool up
= qdict_get_bool(qdict
, "up");
1131 qmp_set_link(name
, up
, &err
);
1132 hmp_handle_error(mon
, &err
);
1135 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
1137 const char *device
= qdict_get_str(qdict
, "device");
1138 const char *password
= qdict_get_str(qdict
, "password");
1141 qmp_block_passwd(true, device
, false, NULL
, password
, &err
);
1142 hmp_handle_error(mon
, &err
);
1145 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
1147 int64_t value
= qdict_get_int(qdict
, "value");
1150 qmp_balloon(value
, &err
);
1152 error_report_err(err
);
1156 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
1158 const char *device
= qdict_get_str(qdict
, "device");
1159 int64_t size
= qdict_get_int(qdict
, "size");
1162 qmp_block_resize(true, device
, false, NULL
, size
, &err
);
1163 hmp_handle_error(mon
, &err
);
1166 void hmp_drive_mirror(Monitor
*mon
, const QDict
*qdict
)
1168 const char *filename
= qdict_get_str(qdict
, "target");
1169 const char *format
= qdict_get_try_str(qdict
, "format");
1170 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1171 bool full
= qdict_get_try_bool(qdict
, "full", false);
1173 DriveMirror mirror
= {
1174 .device
= (char *)qdict_get_str(qdict
, "device"),
1175 .target
= (char *)filename
,
1176 .has_format
= !!format
,
1177 .format
= (char *)format
,
1178 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1180 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
1185 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1186 hmp_handle_error(mon
, &err
);
1189 qmp_drive_mirror(&mirror
, &err
);
1190 hmp_handle_error(mon
, &err
);
1193 void hmp_drive_backup(Monitor
*mon
, const QDict
*qdict
)
1195 const char *device
= qdict_get_str(qdict
, "device");
1196 const char *filename
= qdict_get_str(qdict
, "target");
1197 const char *format
= qdict_get_try_str(qdict
, "format");
1198 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1199 bool full
= qdict_get_try_bool(qdict
, "full", false);
1200 bool compress
= qdict_get_try_bool(qdict
, "compress", false);
1202 DriveBackup backup
= {
1203 .device
= (char *)device
,
1204 .target
= (char *)filename
,
1205 .has_format
= !!format
,
1206 .format
= (char *)format
,
1207 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1209 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
1210 .has_compress
= !!compress
,
1211 .compress
= compress
,
1215 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1216 hmp_handle_error(mon
, &err
);
1220 qmp_drive_backup(&backup
, &err
);
1221 hmp_handle_error(mon
, &err
);
1224 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
1226 const char *device
= qdict_get_str(qdict
, "device");
1227 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
1228 const char *format
= qdict_get_try_str(qdict
, "format");
1229 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1230 enum NewImageMode mode
;
1234 /* In the future, if 'snapshot-file' is not specified, the snapshot
1235 will be taken internally. Today it's actually required. */
1236 error_setg(&err
, QERR_MISSING_PARAMETER
, "snapshot-file");
1237 hmp_handle_error(mon
, &err
);
1241 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
1242 qmp_blockdev_snapshot_sync(true, device
, false, NULL
,
1243 filename
, false, NULL
,
1246 hmp_handle_error(mon
, &err
);
1249 void hmp_snapshot_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");
1255 qmp_blockdev_snapshot_internal_sync(device
, name
, &err
);
1256 hmp_handle_error(mon
, &err
);
1259 void hmp_snapshot_delete_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1261 const char *device
= qdict_get_str(qdict
, "device");
1262 const char *name
= qdict_get_str(qdict
, "name");
1263 const char *id
= qdict_get_try_str(qdict
, "id");
1266 qmp_blockdev_snapshot_delete_internal_sync(device
, !!id
, id
,
1268 hmp_handle_error(mon
, &err
);
1271 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
1273 qmp_migrate_cancel(NULL
);
1276 void hmp_migrate_incoming(Monitor
*mon
, const QDict
*qdict
)
1279 const char *uri
= qdict_get_str(qdict
, "uri");
1281 qmp_migrate_incoming(uri
, &err
);
1283 hmp_handle_error(mon
, &err
);
1286 /* Kept for backwards compatibility */
1287 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
1289 double value
= qdict_get_double(qdict
, "value");
1290 qmp_migrate_set_downtime(value
, NULL
);
1293 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
1295 int64_t value
= qdict_get_int(qdict
, "value");
1298 qmp_migrate_set_cache_size(value
, &err
);
1300 error_report_err(err
);
1305 /* Kept for backwards compatibility */
1306 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
1308 int64_t value
= qdict_get_int(qdict
, "value");
1309 qmp_migrate_set_speed(value
, NULL
);
1312 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
1314 const char *cap
= qdict_get_str(qdict
, "capability");
1315 bool state
= qdict_get_bool(qdict
, "state");
1317 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
1320 for (i
= 0; i
< MIGRATION_CAPABILITY__MAX
; i
++) {
1321 if (strcmp(cap
, MigrationCapability_lookup
[i
]) == 0) {
1322 caps
->value
= g_malloc0(sizeof(*caps
->value
));
1323 caps
->value
->capability
= i
;
1324 caps
->value
->state
= state
;
1326 qmp_migrate_set_capabilities(caps
, &err
);
1331 if (i
== MIGRATION_CAPABILITY__MAX
) {
1332 error_setg(&err
, QERR_INVALID_PARAMETER
, cap
);
1335 qapi_free_MigrationCapabilityStatusList(caps
);
1338 error_report_err(err
);
1342 void hmp_migrate_set_parameter(Monitor
*mon
, const QDict
*qdict
)
1344 const char *param
= qdict_get_str(qdict
, "parameter");
1345 const char *valuestr
= qdict_get_str(qdict
, "value");
1346 uint64_t valuebw
= 0;
1349 bool use_int_value
= false;
1352 for (i
= 0; i
< MIGRATION_PARAMETER__MAX
; i
++) {
1353 if (strcmp(param
, MigrationParameter_lookup
[i
]) == 0) {
1354 MigrationParameters p
= { 0 };
1356 case MIGRATION_PARAMETER_COMPRESS_LEVEL
:
1357 p
.has_compress_level
= true;
1358 use_int_value
= true;
1360 case MIGRATION_PARAMETER_COMPRESS_THREADS
:
1361 p
.has_compress_threads
= true;
1362 use_int_value
= true;
1364 case MIGRATION_PARAMETER_DECOMPRESS_THREADS
:
1365 p
.has_decompress_threads
= true;
1366 use_int_value
= true;
1368 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
:
1369 p
.has_cpu_throttle_initial
= true;
1370 use_int_value
= true;
1372 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
:
1373 p
.has_cpu_throttle_increment
= true;
1374 use_int_value
= true;
1376 case MIGRATION_PARAMETER_TLS_CREDS
:
1377 p
.has_tls_creds
= true;
1378 p
.tls_creds
= (char *) valuestr
;
1380 case MIGRATION_PARAMETER_TLS_HOSTNAME
:
1381 p
.has_tls_hostname
= true;
1382 p
.tls_hostname
= (char *) valuestr
;
1384 case MIGRATION_PARAMETER_MAX_BANDWIDTH
:
1385 p
.has_max_bandwidth
= true;
1386 ret
= qemu_strtosz_MiB(valuestr
, NULL
, &valuebw
);
1387 if (ret
< 0 || valuebw
> INT64_MAX
1388 || (size_t)valuebw
!= valuebw
) {
1389 error_setg(&err
, "Invalid size %s", valuestr
);
1392 p
.max_bandwidth
= valuebw
;
1394 case MIGRATION_PARAMETER_DOWNTIME_LIMIT
:
1395 p
.has_downtime_limit
= true;
1396 use_int_value
= true;
1398 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY
:
1399 p
.has_x_checkpoint_delay
= true;
1400 use_int_value
= true;
1404 if (use_int_value
) {
1405 if (qemu_strtol(valuestr
, NULL
, 10, &valueint
) < 0) {
1406 error_setg(&err
, "Unable to parse '%s' as an int",
1410 /* Set all integers; only one has_FOO will be set, and
1411 * the code ignores the remaining values */
1412 p
.compress_level
= valueint
;
1413 p
.compress_threads
= valueint
;
1414 p
.decompress_threads
= valueint
;
1415 p
.cpu_throttle_initial
= valueint
;
1416 p
.cpu_throttle_increment
= valueint
;
1417 p
.downtime_limit
= valueint
;
1418 p
.x_checkpoint_delay
= valueint
;
1421 qmp_migrate_set_parameters(&p
, &err
);
1426 if (i
== MIGRATION_PARAMETER__MAX
) {
1427 error_setg(&err
, QERR_INVALID_PARAMETER
, param
);
1432 error_report_err(err
);
1436 void hmp_client_migrate_info(Monitor
*mon
, const QDict
*qdict
)
1439 const char *protocol
= qdict_get_str(qdict
, "protocol");
1440 const char *hostname
= qdict_get_str(qdict
, "hostname");
1441 bool has_port
= qdict_haskey(qdict
, "port");
1442 int port
= qdict_get_try_int(qdict
, "port", -1);
1443 bool has_tls_port
= qdict_haskey(qdict
, "tls-port");
1444 int tls_port
= qdict_get_try_int(qdict
, "tls-port", -1);
1445 const char *cert_subject
= qdict_get_try_str(qdict
, "cert-subject");
1447 qmp_client_migrate_info(protocol
, hostname
,
1448 has_port
, port
, has_tls_port
, tls_port
,
1449 !!cert_subject
, cert_subject
, &err
);
1450 hmp_handle_error(mon
, &err
);
1453 void hmp_migrate_start_postcopy(Monitor
*mon
, const QDict
*qdict
)
1456 qmp_migrate_start_postcopy(&err
);
1457 hmp_handle_error(mon
, &err
);
1460 void hmp_x_colo_lost_heartbeat(Monitor
*mon
, const QDict
*qdict
)
1464 qmp_x_colo_lost_heartbeat(&err
);
1465 hmp_handle_error(mon
, &err
);
1468 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
1470 const char *protocol
= qdict_get_str(qdict
, "protocol");
1471 const char *password
= qdict_get_str(qdict
, "password");
1472 const char *connected
= qdict_get_try_str(qdict
, "connected");
1475 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
1476 hmp_handle_error(mon
, &err
);
1479 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
1481 const char *protocol
= qdict_get_str(qdict
, "protocol");
1482 const char *whenstr
= qdict_get_str(qdict
, "time");
1485 qmp_expire_password(protocol
, whenstr
, &err
);
1486 hmp_handle_error(mon
, &err
);
1489 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
1491 bool force
= qdict_get_try_bool(qdict
, "force", false);
1492 const char *device
= qdict_get_str(qdict
, "device");
1495 qmp_eject(true, device
, false, NULL
, true, force
, &err
);
1496 hmp_handle_error(mon
, &err
);
1499 static void hmp_change_read_arg(void *opaque
, const char *password
,
1500 void *readline_opaque
)
1502 qmp_change_vnc_password(password
, NULL
);
1503 monitor_read_command(opaque
, 1);
1506 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
1508 const char *device
= qdict_get_str(qdict
, "device");
1509 const char *target
= qdict_get_str(qdict
, "target");
1510 const char *arg
= qdict_get_try_str(qdict
, "arg");
1511 const char *read_only
= qdict_get_try_str(qdict
, "read-only-mode");
1512 BlockdevChangeReadOnlyMode read_only_mode
= 0;
1515 if (strcmp(device
, "vnc") == 0) {
1518 "Parameter 'read-only-mode' is invalid for VNC\n");
1521 if (strcmp(target
, "passwd") == 0 ||
1522 strcmp(target
, "password") == 0) {
1524 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
1528 qmp_change("vnc", target
, !!arg
, arg
, &err
);
1532 qapi_enum_parse(BlockdevChangeReadOnlyMode_lookup
,
1533 read_only
, BLOCKDEV_CHANGE_READ_ONLY_MODE__MAX
,
1534 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN
, &err
);
1536 hmp_handle_error(mon
, &err
);
1541 qmp_blockdev_change_medium(true, device
, false, NULL
, target
,
1542 !!arg
, arg
, !!read_only
, read_only_mode
,
1545 error_get_class(err
) == ERROR_CLASS_DEVICE_ENCRYPTED
) {
1547 monitor_read_block_device_key(mon
, device
, NULL
, NULL
);
1552 hmp_handle_error(mon
, &err
);
1555 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
1558 BlockIOThrottle throttle
= {
1560 .device
= (char *) qdict_get_str(qdict
, "device"),
1561 .bps
= qdict_get_int(qdict
, "bps"),
1562 .bps_rd
= qdict_get_int(qdict
, "bps_rd"),
1563 .bps_wr
= qdict_get_int(qdict
, "bps_wr"),
1564 .iops
= qdict_get_int(qdict
, "iops"),
1565 .iops_rd
= qdict_get_int(qdict
, "iops_rd"),
1566 .iops_wr
= qdict_get_int(qdict
, "iops_wr"),
1569 qmp_block_set_io_throttle(&throttle
, &err
);
1570 hmp_handle_error(mon
, &err
);
1573 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
1575 Error
*error
= NULL
;
1576 const char *device
= qdict_get_str(qdict
, "device");
1577 const char *base
= qdict_get_try_str(qdict
, "base");
1578 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
1580 qmp_block_stream(true, device
, device
, base
!= NULL
, base
, false, NULL
,
1581 false, NULL
, qdict_haskey(qdict
, "speed"), speed
,
1582 true, BLOCKDEV_ON_ERROR_REPORT
, &error
);
1584 hmp_handle_error(mon
, &error
);
1587 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
1589 Error
*error
= NULL
;
1590 const char *device
= qdict_get_str(qdict
, "device");
1591 int64_t value
= qdict_get_int(qdict
, "speed");
1593 qmp_block_job_set_speed(device
, value
, &error
);
1595 hmp_handle_error(mon
, &error
);
1598 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
1600 Error
*error
= NULL
;
1601 const char *device
= qdict_get_str(qdict
, "device");
1602 bool force
= qdict_get_try_bool(qdict
, "force", false);
1604 qmp_block_job_cancel(device
, true, force
, &error
);
1606 hmp_handle_error(mon
, &error
);
1609 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
1611 Error
*error
= NULL
;
1612 const char *device
= qdict_get_str(qdict
, "device");
1614 qmp_block_job_pause(device
, &error
);
1616 hmp_handle_error(mon
, &error
);
1619 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
1621 Error
*error
= NULL
;
1622 const char *device
= qdict_get_str(qdict
, "device");
1624 qmp_block_job_resume(device
, &error
);
1626 hmp_handle_error(mon
, &error
);
1629 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
1631 Error
*error
= NULL
;
1632 const char *device
= qdict_get_str(qdict
, "device");
1634 qmp_block_job_complete(device
, &error
);
1636 hmp_handle_error(mon
, &error
);
1639 typedef struct HMPMigrationStatus
1643 bool is_block_migration
;
1644 } HMPMigrationStatus
;
1646 static void hmp_migrate_status_cb(void *opaque
)
1648 HMPMigrationStatus
*status
= opaque
;
1649 MigrationInfo
*info
;
1651 info
= qmp_query_migrate(NULL
);
1652 if (!info
->has_status
|| info
->status
== MIGRATION_STATUS_ACTIVE
||
1653 info
->status
== MIGRATION_STATUS_SETUP
) {
1654 if (info
->has_disk
) {
1657 if (info
->disk
->remaining
) {
1658 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1663 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1664 monitor_flush(status
->mon
);
1667 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1000);
1669 if (status
->is_block_migration
) {
1670 monitor_printf(status
->mon
, "\n");
1672 if (info
->has_error_desc
) {
1673 error_report("%s", info
->error_desc
);
1675 monitor_resume(status
->mon
);
1676 timer_del(status
->timer
);
1680 qapi_free_MigrationInfo(info
);
1683 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1685 bool detach
= qdict_get_try_bool(qdict
, "detach", false);
1686 bool blk
= qdict_get_try_bool(qdict
, "blk", false);
1687 bool inc
= qdict_get_try_bool(qdict
, "inc", false);
1688 const char *uri
= qdict_get_str(qdict
, "uri");
1691 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
1693 error_report_err(err
);
1698 HMPMigrationStatus
*status
;
1700 if (monitor_suspend(mon
) < 0) {
1701 monitor_printf(mon
, "terminal does not allow synchronous "
1702 "migration, continuing detached\n");
1706 status
= g_malloc0(sizeof(*status
));
1708 status
->is_block_migration
= blk
|| inc
;
1709 status
->timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, hmp_migrate_status_cb
,
1711 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
1715 void hmp_device_add(Monitor
*mon
, const QDict
*qdict
)
1719 qmp_device_add((QDict
*)qdict
, NULL
, &err
);
1720 hmp_handle_error(mon
, &err
);
1723 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1725 const char *id
= qdict_get_str(qdict
, "id");
1728 qmp_device_del(id
, &err
);
1729 hmp_handle_error(mon
, &err
);
1732 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1735 bool paging
= qdict_get_try_bool(qdict
, "paging", false);
1736 bool zlib
= qdict_get_try_bool(qdict
, "zlib", false);
1737 bool lzo
= qdict_get_try_bool(qdict
, "lzo", false);
1738 bool snappy
= qdict_get_try_bool(qdict
, "snappy", false);
1739 const char *file
= qdict_get_str(qdict
, "filename");
1740 bool has_begin
= qdict_haskey(qdict
, "begin");
1741 bool has_length
= qdict_haskey(qdict
, "length");
1742 bool has_detach
= qdict_haskey(qdict
, "detach");
1745 bool detach
= false;
1746 enum DumpGuestMemoryFormat dump_format
= DUMP_GUEST_MEMORY_FORMAT_ELF
;
1749 if (zlib
+ lzo
+ snappy
> 1) {
1750 error_setg(&err
, "only one of '-z|-l|-s' can be set");
1751 hmp_handle_error(mon
, &err
);
1756 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB
;
1760 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO
;
1764 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY
;
1768 begin
= qdict_get_int(qdict
, "begin");
1771 length
= qdict_get_int(qdict
, "length");
1774 detach
= qdict_get_bool(qdict
, "detach");
1777 prot
= g_strconcat("file:", file
, NULL
);
1779 qmp_dump_guest_memory(paging
, prot
, true, detach
, has_begin
, begin
,
1780 has_length
, length
, true, dump_format
, &err
);
1781 hmp_handle_error(mon
, &err
);
1785 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
1790 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
1795 netdev_add(opts
, &err
);
1797 qemu_opts_del(opts
);
1801 hmp_handle_error(mon
, &err
);
1804 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
1806 const char *id
= qdict_get_str(qdict
, "id");
1809 qmp_netdev_del(id
, &err
);
1810 hmp_handle_error(mon
, &err
);
1813 void hmp_object_add(Monitor
*mon
, const QDict
*qdict
)
1819 opts
= qemu_opts_from_qdict(qemu_find_opts("object"), qdict
, &err
);
1821 hmp_handle_error(mon
, &err
);
1825 obj
= user_creatable_add_opts(opts
, &err
);
1826 qemu_opts_del(opts
);
1829 hmp_handle_error(mon
, &err
);
1836 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
1838 const char *fdname
= qdict_get_str(qdict
, "fdname");
1841 qmp_getfd(fdname
, &err
);
1842 hmp_handle_error(mon
, &err
);
1845 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
1847 const char *fdname
= qdict_get_str(qdict
, "fdname");
1850 qmp_closefd(fdname
, &err
);
1851 hmp_handle_error(mon
, &err
);
1854 void hmp_sendkey(Monitor
*mon
, const QDict
*qdict
)
1856 const char *keys
= qdict_get_str(qdict
, "keys");
1857 KeyValueList
*keylist
, *head
= NULL
, *tmp
= NULL
;
1858 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
1859 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
1865 separator
= strchr(keys
, '-');
1866 keyname_len
= separator
? separator
- keys
: strlen(keys
);
1868 /* Be compatible with old interface, convert user inputted "<" */
1869 if (keys
[0] == '<' && keyname_len
== 1) {
1874 keylist
= g_malloc0(sizeof(*keylist
));
1875 keylist
->value
= g_malloc0(sizeof(*keylist
->value
));
1881 tmp
->next
= keylist
;
1885 if (strstart(keys
, "0x", NULL
)) {
1887 int value
= strtoul(keys
, &endp
, 0);
1888 assert(endp
<= keys
+ keyname_len
);
1889 if (endp
!= keys
+ keyname_len
) {
1892 keylist
->value
->type
= KEY_VALUE_KIND_NUMBER
;
1893 keylist
->value
->u
.number
.data
= value
;
1895 int idx
= index_from_key(keys
, keyname_len
);
1896 if (idx
== Q_KEY_CODE__MAX
) {
1899 keylist
->value
->type
= KEY_VALUE_KIND_QCODE
;
1900 keylist
->value
->u
.qcode
.data
= idx
;
1906 keys
= separator
+ 1;
1909 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
1910 hmp_handle_error(mon
, &err
);
1913 qapi_free_KeyValueList(head
);
1917 monitor_printf(mon
, "invalid parameter: %.*s\n", keyname_len
, keys
);
1921 void hmp_screendump(Monitor
*mon
, const QDict
*qdict
)
1923 const char *filename
= qdict_get_str(qdict
, "filename");
1926 qmp_screendump(filename
, &err
);
1927 hmp_handle_error(mon
, &err
);
1930 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
1932 const char *uri
= qdict_get_str(qdict
, "uri");
1933 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
1934 bool all
= qdict_get_try_bool(qdict
, "all", false);
1935 Error
*local_err
= NULL
;
1936 BlockInfoList
*block_list
, *info
;
1937 SocketAddress
*addr
;
1939 if (writable
&& !all
) {
1940 error_setg(&local_err
, "-w only valid together with -a");
1944 /* First check if the address is valid and start the server. */
1945 addr
= socket_parse(uri
, &local_err
);
1946 if (local_err
!= NULL
) {
1950 qmp_nbd_server_start(addr
, false, NULL
, &local_err
);
1951 qapi_free_SocketAddress(addr
);
1952 if (local_err
!= NULL
) {
1960 /* Then try adding all block devices. If one fails, close all and
1963 block_list
= qmp_query_block(NULL
);
1965 for (info
= block_list
; info
; info
= info
->next
) {
1966 if (!info
->value
->has_inserted
) {
1970 qmp_nbd_server_add(info
->value
->device
, true, writable
, &local_err
);
1972 if (local_err
!= NULL
) {
1973 qmp_nbd_server_stop(NULL
);
1978 qapi_free_BlockInfoList(block_list
);
1981 hmp_handle_error(mon
, &local_err
);
1984 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
1986 const char *device
= qdict_get_str(qdict
, "device");
1987 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
1988 Error
*local_err
= NULL
;
1990 qmp_nbd_server_add(device
, true, writable
, &local_err
);
1992 if (local_err
!= NULL
) {
1993 hmp_handle_error(mon
, &local_err
);
1997 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
2001 qmp_nbd_server_stop(&err
);
2002 hmp_handle_error(mon
, &err
);
2005 void hmp_cpu_add(Monitor
*mon
, const QDict
*qdict
)
2010 cpuid
= qdict_get_int(qdict
, "id");
2011 qmp_cpu_add(cpuid
, &err
);
2012 hmp_handle_error(mon
, &err
);
2015 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
2017 const char *args
= qdict_get_str(qdict
, "args");
2021 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
, true);
2023 error_setg(&err
, "Parsing chardev args failed");
2025 qemu_chr_new_from_opts(opts
, &err
);
2026 qemu_opts_del(opts
);
2028 hmp_handle_error(mon
, &err
);
2031 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
2033 Error
*local_err
= NULL
;
2035 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
2036 hmp_handle_error(mon
, &local_err
);
2039 void hmp_qemu_io(Monitor
*mon
, const QDict
*qdict
)
2042 BlockBackend
*local_blk
= NULL
;
2043 AioContext
*aio_context
;
2044 const char* device
= qdict_get_str(qdict
, "device");
2045 const char* command
= qdict_get_str(qdict
, "command");
2049 blk
= blk_by_name(device
);
2051 BlockDriverState
*bs
= bdrv_lookup_bs(NULL
, device
, &err
);
2053 blk
= local_blk
= blk_new(0, BLK_PERM_ALL
);
2054 ret
= blk_insert_bs(blk
, bs
, &err
);
2063 aio_context
= blk_get_aio_context(blk
);
2064 aio_context_acquire(aio_context
);
2067 * Notably absent: Proper permission management. This is sad, but it seems
2068 * almost impossible to achieve without changing the semantics and thereby
2069 * limiting the use cases of the qemu-io HMP command.
2071 * In an ideal world we would unconditionally create a new BlockBackend for
2072 * qemuio_command(), but we have commands like 'reopen' and want them to
2073 * take effect on the exact BlockBackend whose name the user passed instead
2074 * of just on a temporary copy of it.
2076 * Another problem is that deleting the temporary BlockBackend involves
2077 * draining all requests on it first, but some qemu-iotests cases want to
2078 * issue multiple aio_read/write requests and expect them to complete in
2079 * the background while the monitor has already returned.
2081 * This is also what prevents us from saving the original permissions and
2082 * restoring them later: We can't revoke permissions until all requests
2083 * have completed, and we don't know when that is nor can we really let
2084 * anything else run before we have revoken them to avoid race conditions.
2086 * What happens now is that command() in qemu-io-cmds.c can extend the
2087 * permissions if necessary for the qemu-io command. And they simply stay
2088 * extended, possibly resulting in a read-only guest device keeping write
2089 * permissions. Ugly, but it appears to be the lesser evil.
2091 qemuio_command(blk
, command
);
2093 aio_context_release(aio_context
);
2096 blk_unref(local_blk
);
2097 hmp_handle_error(mon
, &err
);
2100 void hmp_object_del(Monitor
*mon
, const QDict
*qdict
)
2102 const char *id
= qdict_get_str(qdict
, "id");
2105 user_creatable_del(id
, &err
);
2106 hmp_handle_error(mon
, &err
);
2109 void hmp_info_memdev(Monitor
*mon
, const QDict
*qdict
)
2112 MemdevList
*memdev_list
= qmp_query_memdev(&err
);
2113 MemdevList
*m
= memdev_list
;
2118 v
= string_output_visitor_new(false, &str
);
2119 visit_type_uint16List(v
, NULL
, &m
->value
->host_nodes
, NULL
);
2120 monitor_printf(mon
, "memory backend: %s\n", m
->value
->id
);
2121 monitor_printf(mon
, " size: %" PRId64
"\n", m
->value
->size
);
2122 monitor_printf(mon
, " merge: %s\n",
2123 m
->value
->merge
? "true" : "false");
2124 monitor_printf(mon
, " dump: %s\n",
2125 m
->value
->dump
? "true" : "false");
2126 monitor_printf(mon
, " prealloc: %s\n",
2127 m
->value
->prealloc
? "true" : "false");
2128 monitor_printf(mon
, " policy: %s\n",
2129 HostMemPolicy_lookup
[m
->value
->policy
]);
2130 visit_complete(v
, &str
);
2131 monitor_printf(mon
, " host nodes: %s\n", str
);
2138 monitor_printf(mon
, "\n");
2140 qapi_free_MemdevList(memdev_list
);
2143 void hmp_info_memory_devices(Monitor
*mon
, const QDict
*qdict
)
2146 MemoryDeviceInfoList
*info_list
= qmp_query_memory_devices(&err
);
2147 MemoryDeviceInfoList
*info
;
2148 MemoryDeviceInfo
*value
;
2149 PCDIMMDeviceInfo
*di
;
2151 for (info
= info_list
; info
; info
= info
->next
) {
2152 value
= info
->value
;
2155 switch (value
->type
) {
2156 case MEMORY_DEVICE_INFO_KIND_DIMM
:
2157 di
= value
->u
.dimm
.data
;
2159 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
2160 MemoryDeviceInfoKind_lookup
[value
->type
],
2161 di
->id
? di
->id
: "");
2162 monitor_printf(mon
, " addr: 0x%" PRIx64
"\n", di
->addr
);
2163 monitor_printf(mon
, " slot: %" PRId64
"\n", di
->slot
);
2164 monitor_printf(mon
, " node: %" PRId64
"\n", di
->node
);
2165 monitor_printf(mon
, " size: %" PRIu64
"\n", di
->size
);
2166 monitor_printf(mon
, " memdev: %s\n", di
->memdev
);
2167 monitor_printf(mon
, " hotplugged: %s\n",
2168 di
->hotplugged
? "true" : "false");
2169 monitor_printf(mon
, " hotpluggable: %s\n",
2170 di
->hotpluggable
? "true" : "false");
2178 qapi_free_MemoryDeviceInfoList(info_list
);
2181 void hmp_info_iothreads(Monitor
*mon
, const QDict
*qdict
)
2183 IOThreadInfoList
*info_list
= qmp_query_iothreads(NULL
);
2184 IOThreadInfoList
*info
;
2185 IOThreadInfo
*value
;
2187 for (info
= info_list
; info
; info
= info
->next
) {
2188 value
= info
->value
;
2189 monitor_printf(mon
, "%s:\n", value
->id
);
2190 monitor_printf(mon
, " thread_id=%" PRId64
"\n", value
->thread_id
);
2191 monitor_printf(mon
, " poll-max-ns=%" PRId64
"\n", value
->poll_max_ns
);
2192 monitor_printf(mon
, " poll-grow=%" PRId64
"\n", value
->poll_grow
);
2193 monitor_printf(mon
, " poll-shrink=%" PRId64
"\n", value
->poll_shrink
);
2196 qapi_free_IOThreadInfoList(info_list
);
2199 void hmp_qom_list(Monitor
*mon
, const QDict
*qdict
)
2201 const char *path
= qdict_get_try_str(qdict
, "path");
2202 ObjectPropertyInfoList
*list
;
2206 monitor_printf(mon
, "/\n");
2210 list
= qmp_qom_list(path
, &err
);
2212 ObjectPropertyInfoList
*start
= list
;
2213 while (list
!= NULL
) {
2214 ObjectPropertyInfo
*value
= list
->value
;
2216 monitor_printf(mon
, "%s (%s)\n",
2217 value
->name
, value
->type
);
2220 qapi_free_ObjectPropertyInfoList(start
);
2222 hmp_handle_error(mon
, &err
);
2225 void hmp_qom_set(Monitor
*mon
, const QDict
*qdict
)
2227 const char *path
= qdict_get_str(qdict
, "path");
2228 const char *property
= qdict_get_str(qdict
, "property");
2229 const char *value
= qdict_get_str(qdict
, "value");
2231 bool ambiguous
= false;
2234 obj
= object_resolve_path(path
, &ambiguous
);
2236 error_set(&err
, ERROR_CLASS_DEVICE_NOT_FOUND
,
2237 "Device '%s' not found", path
);
2240 monitor_printf(mon
, "Warning: Path '%s' is ambiguous\n", path
);
2242 object_property_parse(obj
, value
, property
, &err
);
2244 hmp_handle_error(mon
, &err
);
2247 void hmp_rocker(Monitor
*mon
, const QDict
*qdict
)
2249 const char *name
= qdict_get_str(qdict
, "name");
2250 RockerSwitch
*rocker
;
2253 rocker
= qmp_query_rocker(name
, &err
);
2255 hmp_handle_error(mon
, &err
);
2259 monitor_printf(mon
, "name: %s\n", rocker
->name
);
2260 monitor_printf(mon
, "id: 0x%" PRIx64
"\n", rocker
->id
);
2261 monitor_printf(mon
, "ports: %d\n", rocker
->ports
);
2263 qapi_free_RockerSwitch(rocker
);
2266 void hmp_rocker_ports(Monitor
*mon
, const QDict
*qdict
)
2268 RockerPortList
*list
, *port
;
2269 const char *name
= qdict_get_str(qdict
, "name");
2272 list
= qmp_query_rocker_ports(name
, &err
);
2274 hmp_handle_error(mon
, &err
);
2278 monitor_printf(mon
, " ena/ speed/ auto\n");
2279 monitor_printf(mon
, " port link duplex neg?\n");
2281 for (port
= list
; port
; port
= port
->next
) {
2282 monitor_printf(mon
, "%10s %-4s %-3s %2s %-3s\n",
2284 port
->value
->enabled
? port
->value
->link_up
?
2285 "up" : "down" : "!ena",
2286 port
->value
->speed
== 10000 ? "10G" : "??",
2287 port
->value
->duplex
? "FD" : "HD",
2288 port
->value
->autoneg
? "Yes" : "No");
2291 qapi_free_RockerPortList(list
);
2294 void hmp_rocker_of_dpa_flows(Monitor
*mon
, const QDict
*qdict
)
2296 RockerOfDpaFlowList
*list
, *info
;
2297 const char *name
= qdict_get_str(qdict
, "name");
2298 uint32_t tbl_id
= qdict_get_try_int(qdict
, "tbl_id", -1);
2301 list
= qmp_query_rocker_of_dpa_flows(name
, tbl_id
!= -1, tbl_id
, &err
);
2303 hmp_handle_error(mon
, &err
);
2307 monitor_printf(mon
, "prio tbl hits key(mask) --> actions\n");
2309 for (info
= list
; info
; info
= info
->next
) {
2310 RockerOfDpaFlow
*flow
= info
->value
;
2311 RockerOfDpaFlowKey
*key
= flow
->key
;
2312 RockerOfDpaFlowMask
*mask
= flow
->mask
;
2313 RockerOfDpaFlowAction
*action
= flow
->action
;
2316 monitor_printf(mon
, "%-4d %-3d %-4" PRIu64
,
2317 key
->priority
, key
->tbl_id
, flow
->hits
);
2319 monitor_printf(mon
, "%-4d %-3d ",
2320 key
->priority
, key
->tbl_id
);
2323 if (key
->has_in_pport
) {
2324 monitor_printf(mon
, " pport %d", key
->in_pport
);
2325 if (mask
->has_in_pport
) {
2326 monitor_printf(mon
, "(0x%x)", mask
->in_pport
);
2330 if (key
->has_vlan_id
) {
2331 monitor_printf(mon
, " vlan %d",
2332 key
->vlan_id
& VLAN_VID_MASK
);
2333 if (mask
->has_vlan_id
) {
2334 monitor_printf(mon
, "(0x%x)", mask
->vlan_id
);
2338 if (key
->has_tunnel_id
) {
2339 monitor_printf(mon
, " tunnel %d", key
->tunnel_id
);
2340 if (mask
->has_tunnel_id
) {
2341 monitor_printf(mon
, "(0x%x)", mask
->tunnel_id
);
2345 if (key
->has_eth_type
) {
2346 switch (key
->eth_type
) {
2348 monitor_printf(mon
, " ARP");
2351 monitor_printf(mon
, " IP");
2354 monitor_printf(mon
, " IPv6");
2357 monitor_printf(mon
, " LACP");
2360 monitor_printf(mon
, " LLDP");
2363 monitor_printf(mon
, " eth type 0x%04x", key
->eth_type
);
2368 if (key
->has_eth_src
) {
2369 if ((strcmp(key
->eth_src
, "01:00:00:00:00:00") == 0) &&
2370 (mask
->has_eth_src
) &&
2371 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2372 monitor_printf(mon
, " src <any mcast/bcast>");
2373 } else if ((strcmp(key
->eth_src
, "00:00:00:00:00:00") == 0) &&
2374 (mask
->has_eth_src
) &&
2375 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2376 monitor_printf(mon
, " src <any ucast>");
2378 monitor_printf(mon
, " src %s", key
->eth_src
);
2379 if (mask
->has_eth_src
) {
2380 monitor_printf(mon
, "(%s)", mask
->eth_src
);
2385 if (key
->has_eth_dst
) {
2386 if ((strcmp(key
->eth_dst
, "01:00:00:00:00:00") == 0) &&
2387 (mask
->has_eth_dst
) &&
2388 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2389 monitor_printf(mon
, " dst <any mcast/bcast>");
2390 } else if ((strcmp(key
->eth_dst
, "00:00:00:00:00:00") == 0) &&
2391 (mask
->has_eth_dst
) &&
2392 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2393 monitor_printf(mon
, " dst <any ucast>");
2395 monitor_printf(mon
, " dst %s", key
->eth_dst
);
2396 if (mask
->has_eth_dst
) {
2397 monitor_printf(mon
, "(%s)", mask
->eth_dst
);
2402 if (key
->has_ip_proto
) {
2403 monitor_printf(mon
, " proto %d", key
->ip_proto
);
2404 if (mask
->has_ip_proto
) {
2405 monitor_printf(mon
, "(0x%x)", mask
->ip_proto
);
2409 if (key
->has_ip_tos
) {
2410 monitor_printf(mon
, " TOS %d", key
->ip_tos
);
2411 if (mask
->has_ip_tos
) {
2412 monitor_printf(mon
, "(0x%x)", mask
->ip_tos
);
2416 if (key
->has_ip_dst
) {
2417 monitor_printf(mon
, " dst %s", key
->ip_dst
);
2420 if (action
->has_goto_tbl
|| action
->has_group_id
||
2421 action
->has_new_vlan_id
) {
2422 monitor_printf(mon
, " -->");
2425 if (action
->has_new_vlan_id
) {
2426 monitor_printf(mon
, " apply new vlan %d",
2427 ntohs(action
->new_vlan_id
));
2430 if (action
->has_group_id
) {
2431 monitor_printf(mon
, " write group 0x%08x", action
->group_id
);
2434 if (action
->has_goto_tbl
) {
2435 monitor_printf(mon
, " goto tbl %d", action
->goto_tbl
);
2438 monitor_printf(mon
, "\n");
2441 qapi_free_RockerOfDpaFlowList(list
);
2444 void hmp_rocker_of_dpa_groups(Monitor
*mon
, const QDict
*qdict
)
2446 RockerOfDpaGroupList
*list
, *g
;
2447 const char *name
= qdict_get_str(qdict
, "name");
2448 uint8_t type
= qdict_get_try_int(qdict
, "type", 9);
2452 list
= qmp_query_rocker_of_dpa_groups(name
, type
!= 9, type
, &err
);
2454 hmp_handle_error(mon
, &err
);
2458 monitor_printf(mon
, "id (decode) --> buckets\n");
2460 for (g
= list
; g
; g
= g
->next
) {
2461 RockerOfDpaGroup
*group
= g
->value
;
2463 monitor_printf(mon
, "0x%08x", group
->id
);
2465 monitor_printf(mon
, " (type %s", group
->type
== 0 ? "L2 interface" :
2466 group
->type
== 1 ? "L2 rewrite" :
2467 group
->type
== 2 ? "L3 unicast" :
2468 group
->type
== 3 ? "L2 multicast" :
2469 group
->type
== 4 ? "L2 flood" :
2470 group
->type
== 5 ? "L3 interface" :
2471 group
->type
== 6 ? "L3 multicast" :
2472 group
->type
== 7 ? "L3 ECMP" :
2473 group
->type
== 8 ? "L2 overlay" :
2476 if (group
->has_vlan_id
) {
2477 monitor_printf(mon
, " vlan %d", group
->vlan_id
);
2480 if (group
->has_pport
) {
2481 monitor_printf(mon
, " pport %d", group
->pport
);
2484 if (group
->has_index
) {
2485 monitor_printf(mon
, " index %d", group
->index
);
2488 monitor_printf(mon
, ") -->");
2490 if (group
->has_set_vlan_id
&& group
->set_vlan_id
) {
2492 monitor_printf(mon
, " set vlan %d",
2493 group
->set_vlan_id
& VLAN_VID_MASK
);
2496 if (group
->has_set_eth_src
) {
2499 monitor_printf(mon
, " set");
2501 monitor_printf(mon
, " src %s", group
->set_eth_src
);
2504 if (group
->has_set_eth_dst
) {
2507 monitor_printf(mon
, " set");
2509 monitor_printf(mon
, " dst %s", group
->set_eth_dst
);
2514 if (group
->has_ttl_check
&& group
->ttl_check
) {
2515 monitor_printf(mon
, " check TTL");
2518 if (group
->has_group_id
&& group
->group_id
) {
2519 monitor_printf(mon
, " group id 0x%08x", group
->group_id
);
2522 if (group
->has_pop_vlan
&& group
->pop_vlan
) {
2523 monitor_printf(mon
, " pop vlan");
2526 if (group
->has_out_pport
) {
2527 monitor_printf(mon
, " out pport %d", group
->out_pport
);
2530 if (group
->has_group_ids
) {
2531 struct uint32List
*id
;
2533 monitor_printf(mon
, " groups [");
2534 for (id
= group
->group_ids
; id
; id
= id
->next
) {
2535 monitor_printf(mon
, "0x%08x", id
->value
);
2537 monitor_printf(mon
, ",");
2540 monitor_printf(mon
, "]");
2543 monitor_printf(mon
, "\n");
2546 qapi_free_RockerOfDpaGroupList(list
);
2549 void hmp_info_dump(Monitor
*mon
, const QDict
*qdict
)
2551 DumpQueryResult
*result
= qmp_query_dump(NULL
);
2553 assert(result
&& result
->status
< DUMP_STATUS__MAX
);
2554 monitor_printf(mon
, "Status: %s\n", DumpStatus_lookup
[result
->status
]);
2556 if (result
->status
== DUMP_STATUS_ACTIVE
) {
2558 assert(result
->total
!= 0);
2559 percent
= 100.0 * result
->completed
/ result
->total
;
2560 monitor_printf(mon
, "Finished: %.2f %%\n", percent
);
2563 qapi_free_DumpQueryResult(result
);
2566 void hmp_hotpluggable_cpus(Monitor
*mon
, const QDict
*qdict
)
2569 HotpluggableCPUList
*l
= qmp_query_hotpluggable_cpus(&err
);
2570 HotpluggableCPUList
*saved
= l
;
2571 CpuInstanceProperties
*c
;
2574 hmp_handle_error(mon
, &err
);
2578 monitor_printf(mon
, "Hotpluggable CPUs:\n");
2580 monitor_printf(mon
, " type: \"%s\"\n", l
->value
->type
);
2581 monitor_printf(mon
, " vcpus_count: \"%" PRIu64
"\"\n",
2582 l
->value
->vcpus_count
);
2583 if (l
->value
->has_qom_path
) {
2584 monitor_printf(mon
, " qom_path: \"%s\"\n", l
->value
->qom_path
);
2587 c
= l
->value
->props
;
2588 monitor_printf(mon
, " CPUInstance Properties:\n");
2589 if (c
->has_node_id
) {
2590 monitor_printf(mon
, " node-id: \"%" PRIu64
"\"\n", c
->node_id
);
2592 if (c
->has_socket_id
) {
2593 monitor_printf(mon
, " socket-id: \"%" PRIu64
"\"\n", c
->socket_id
);
2595 if (c
->has_core_id
) {
2596 monitor_printf(mon
, " core-id: \"%" PRIu64
"\"\n", c
->core_id
);
2598 if (c
->has_thread_id
) {
2599 monitor_printf(mon
, " thread-id: \"%" PRIu64
"\"\n", c
->thread_id
);
2605 qapi_free_HotpluggableCPUList(saved
);
2608 void hmp_info_vm_generation_id(Monitor
*mon
, const QDict
*qdict
)
2611 GuidInfo
*info
= qmp_query_vm_generation_id(&err
);
2613 monitor_printf(mon
, "%s\n", info
->guid
);
2615 hmp_handle_error(mon
, &err
);
2616 qapi_free_GuidInfo(info
);