2 * Human Monitor Interface
4 * Copyright IBM, Corp. 2011
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
12 * Contributions after 2012-01-13 are licensed under the terms of the
13 * GNU GPL, version 2 or (at your option) any later version.
18 #include "sysemu/char.h"
19 #include "sysemu/block-backend.h"
20 #include "qemu/option.h"
21 #include "qemu/timer.h"
22 #include "qmp-commands.h"
23 #include "qemu/sockets.h"
24 #include "monitor/monitor.h"
25 #include "qapi/opts-visitor.h"
26 #include "qapi/string-output-visitor.h"
27 #include "qapi-visit.h"
28 #include "ui/console.h"
29 #include "block/qapi.h"
32 static void hmp_handle_error(Monitor
*mon
, Error
**errp
)
36 monitor_printf(mon
, "%s\n", error_get_pretty(*errp
));
41 void hmp_info_name(Monitor
*mon
, const QDict
*qdict
)
45 info
= qmp_query_name(NULL
);
47 monitor_printf(mon
, "%s\n", info
->name
);
49 qapi_free_NameInfo(info
);
52 void hmp_info_version(Monitor
*mon
, const QDict
*qdict
)
56 info
= qmp_query_version(NULL
);
58 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
59 info
->qemu
.major
, info
->qemu
.minor
, info
->qemu
.micro
,
62 qapi_free_VersionInfo(info
);
65 void hmp_info_kvm(Monitor
*mon
, const QDict
*qdict
)
69 info
= qmp_query_kvm(NULL
);
70 monitor_printf(mon
, "kvm support: ");
72 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
74 monitor_printf(mon
, "not compiled\n");
77 qapi_free_KvmInfo(info
);
80 void hmp_info_status(Monitor
*mon
, const QDict
*qdict
)
84 info
= qmp_query_status(NULL
);
86 monitor_printf(mon
, "VM status: %s%s",
87 info
->running
? "running" : "paused",
88 info
->singlestep
? " (single step mode)" : "");
90 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
91 monitor_printf(mon
, " (%s)", RunState_lookup
[info
->status
]);
94 monitor_printf(mon
, "\n");
96 qapi_free_StatusInfo(info
);
99 void hmp_info_uuid(Monitor
*mon
, const QDict
*qdict
)
103 info
= qmp_query_uuid(NULL
);
104 monitor_printf(mon
, "%s\n", info
->UUID
);
105 qapi_free_UuidInfo(info
);
108 void hmp_info_chardev(Monitor
*mon
, const QDict
*qdict
)
110 ChardevInfoList
*char_info
, *info
;
112 char_info
= qmp_query_chardev(NULL
);
113 for (info
= char_info
; info
; info
= info
->next
) {
114 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
115 info
->value
->filename
);
118 qapi_free_ChardevInfoList(char_info
);
121 void hmp_info_mice(Monitor
*mon
, const QDict
*qdict
)
123 MouseInfoList
*mice_list
, *mouse
;
125 mice_list
= qmp_query_mice(NULL
);
127 monitor_printf(mon
, "No mouse devices connected\n");
131 for (mouse
= mice_list
; mouse
; mouse
= mouse
->next
) {
132 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s%s\n",
133 mouse
->value
->current
? '*' : ' ',
134 mouse
->value
->index
, mouse
->value
->name
,
135 mouse
->value
->absolute
? " (absolute)" : "");
138 qapi_free_MouseInfoList(mice_list
);
141 void hmp_info_migrate(Monitor
*mon
, const QDict
*qdict
)
144 MigrationCapabilityStatusList
*caps
, *cap
;
146 info
= qmp_query_migrate(NULL
);
147 caps
= qmp_query_migrate_capabilities(NULL
);
149 /* do not display parameters during setup */
150 if (info
->has_status
&& caps
) {
151 monitor_printf(mon
, "capabilities: ");
152 for (cap
= caps
; cap
; cap
= cap
->next
) {
153 monitor_printf(mon
, "%s: %s ",
154 MigrationCapability_lookup
[cap
->value
->capability
],
155 cap
->value
->state
? "on" : "off");
157 monitor_printf(mon
, "\n");
160 if (info
->has_status
) {
161 monitor_printf(mon
, "Migration status: %s\n", info
->status
);
162 monitor_printf(mon
, "total time: %" PRIu64
" milliseconds\n",
164 if (info
->has_expected_downtime
) {
165 monitor_printf(mon
, "expected downtime: %" PRIu64
" milliseconds\n",
166 info
->expected_downtime
);
168 if (info
->has_downtime
) {
169 monitor_printf(mon
, "downtime: %" PRIu64
" milliseconds\n",
172 if (info
->has_setup_time
) {
173 monitor_printf(mon
, "setup: %" PRIu64
" milliseconds\n",
179 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
180 info
->ram
->transferred
>> 10);
181 monitor_printf(mon
, "throughput: %0.2f mbps\n",
183 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
184 info
->ram
->remaining
>> 10);
185 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
186 info
->ram
->total
>> 10);
187 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
188 info
->ram
->duplicate
);
189 monitor_printf(mon
, "skipped: %" PRIu64
" pages\n",
191 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
193 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
194 info
->ram
->normal_bytes
>> 10);
195 monitor_printf(mon
, "dirty sync count: %" PRIu64
"\n",
196 info
->ram
->dirty_sync_count
);
197 if (info
->ram
->dirty_pages_rate
) {
198 monitor_printf(mon
, "dirty pages rate: %" PRIu64
" pages\n",
199 info
->ram
->dirty_pages_rate
);
203 if (info
->has_disk
) {
204 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
205 info
->disk
->transferred
>> 10);
206 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
207 info
->disk
->remaining
>> 10);
208 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
209 info
->disk
->total
>> 10);
212 if (info
->has_xbzrle_cache
) {
213 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
214 info
->xbzrle_cache
->cache_size
);
215 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
216 info
->xbzrle_cache
->bytes
>> 10);
217 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
218 info
->xbzrle_cache
->pages
);
219 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
"\n",
220 info
->xbzrle_cache
->cache_miss
);
221 monitor_printf(mon
, "xbzrle cache miss rate: %0.2f\n",
222 info
->xbzrle_cache
->cache_miss_rate
);
223 monitor_printf(mon
, "xbzrle overflow : %" PRIu64
"\n",
224 info
->xbzrle_cache
->overflow
);
227 qapi_free_MigrationInfo(info
);
228 qapi_free_MigrationCapabilityStatusList(caps
);
231 void hmp_info_migrate_capabilities(Monitor
*mon
, const QDict
*qdict
)
233 MigrationCapabilityStatusList
*caps
, *cap
;
235 caps
= qmp_query_migrate_capabilities(NULL
);
238 monitor_printf(mon
, "capabilities: ");
239 for (cap
= caps
; cap
; cap
= cap
->next
) {
240 monitor_printf(mon
, "%s: %s ",
241 MigrationCapability_lookup
[cap
->value
->capability
],
242 cap
->value
->state
? "on" : "off");
244 monitor_printf(mon
, "\n");
247 qapi_free_MigrationCapabilityStatusList(caps
);
250 void hmp_info_migrate_cache_size(Monitor
*mon
, const QDict
*qdict
)
252 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
253 qmp_query_migrate_cache_size(NULL
) >> 10);
256 void hmp_info_cpus(Monitor
*mon
, const QDict
*qdict
)
258 CpuInfoList
*cpu_list
, *cpu
;
260 cpu_list
= qmp_query_cpus(NULL
);
262 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
265 if (cpu
->value
->CPU
== monitor_get_cpu_index()) {
269 monitor_printf(mon
, "%c CPU #%" PRId64
":", active
, cpu
->value
->CPU
);
271 if (cpu
->value
->has_pc
) {
272 monitor_printf(mon
, " pc=0x%016" PRIx64
, cpu
->value
->pc
);
274 if (cpu
->value
->has_nip
) {
275 monitor_printf(mon
, " nip=0x%016" PRIx64
, cpu
->value
->nip
);
277 if (cpu
->value
->has_npc
) {
278 monitor_printf(mon
, " npc=0x%016" PRIx64
, cpu
->value
->npc
);
280 if (cpu
->value
->has_PC
) {
281 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->PC
);
284 if (cpu
->value
->halted
) {
285 monitor_printf(mon
, " (halted)");
288 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
291 qapi_free_CpuInfoList(cpu_list
);
294 static void print_block_info(Monitor
*mon
, BlockInfo
*info
,
295 BlockDeviceInfo
*inserted
, bool verbose
)
297 ImageInfo
*image_info
;
299 assert(!info
|| !info
->has_inserted
|| info
->inserted
== inserted
);
302 monitor_printf(mon
, "%s", info
->device
);
303 if (inserted
&& inserted
->has_node_name
) {
304 monitor_printf(mon
, " (%s)", inserted
->node_name
);
308 monitor_printf(mon
, "%s",
309 inserted
->has_node_name
310 ? inserted
->node_name
315 monitor_printf(mon
, ": %s (%s%s%s)\n",
318 inserted
->ro
? ", read-only" : "",
319 inserted
->encrypted
? ", encrypted" : "");
321 monitor_printf(mon
, ": [not inserted]\n");
325 if (info
->has_io_status
&& info
->io_status
!= BLOCK_DEVICE_IO_STATUS_OK
) {
326 monitor_printf(mon
, " I/O status: %s\n",
327 BlockDeviceIoStatus_lookup
[info
->io_status
]);
330 if (info
->removable
) {
331 monitor_printf(mon
, " Removable device: %slocked, tray %s\n",
332 info
->locked
? "" : "not ",
333 info
->tray_open
? "open" : "closed");
342 monitor_printf(mon
, " Cache mode: %s%s%s\n",
343 inserted
->cache
->writeback
? "writeback" : "writethrough",
344 inserted
->cache
->direct
? ", direct" : "",
345 inserted
->cache
->no_flush
? ", ignore flushes" : "");
347 if (inserted
->has_backing_file
) {
350 "(chain depth: %" PRId64
")\n",
351 inserted
->backing_file
,
352 inserted
->backing_file_depth
);
355 if (inserted
->detect_zeroes
!= BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF
) {
356 monitor_printf(mon
, " Detect zeroes: %s\n",
357 BlockdevDetectZeroesOptions_lookup
[inserted
->detect_zeroes
]);
360 if (inserted
->bps
|| inserted
->bps_rd
|| inserted
->bps_wr
||
361 inserted
->iops
|| inserted
->iops_rd
|| inserted
->iops_wr
)
363 monitor_printf(mon
, " I/O throttling: bps=%" PRId64
364 " bps_rd=%" PRId64
" bps_wr=%" PRId64
366 " bps_rd_max=%" PRId64
367 " bps_wr_max=%" PRId64
368 " iops=%" PRId64
" iops_rd=%" PRId64
371 " iops_rd_max=%" PRId64
372 " iops_wr_max=%" PRId64
373 " iops_size=%" PRId64
"\n",
378 inserted
->bps_rd_max
,
379 inserted
->bps_wr_max
,
384 inserted
->iops_rd_max
,
385 inserted
->iops_wr_max
,
386 inserted
->iops_size
);
390 monitor_printf(mon
, "\nImages:\n");
391 image_info
= inserted
->image
;
393 bdrv_image_info_dump((fprintf_function
)monitor_printf
,
395 if (image_info
->has_backing_image
) {
396 image_info
= image_info
->backing_image
;
404 void hmp_info_block(Monitor
*mon
, const QDict
*qdict
)
406 BlockInfoList
*block_list
, *info
;
407 BlockDeviceInfoList
*blockdev_list
, *blockdev
;
408 const char *device
= qdict_get_try_str(qdict
, "device");
409 bool verbose
= qdict_get_try_bool(qdict
, "verbose", 0);
410 bool nodes
= qdict_get_try_bool(qdict
, "nodes", 0);
411 bool printed
= false;
413 /* Print BlockBackend information */
415 block_list
= qmp_query_block(false);
420 for (info
= block_list
; info
; info
= info
->next
) {
421 if (device
&& strcmp(device
, info
->value
->device
)) {
425 if (info
!= block_list
) {
426 monitor_printf(mon
, "\n");
429 print_block_info(mon
, info
->value
, info
->value
->has_inserted
430 ? info
->value
->inserted
: NULL
,
435 qapi_free_BlockInfoList(block_list
);
437 if ((!device
&& !nodes
) || printed
) {
441 /* Print node information */
442 blockdev_list
= qmp_query_named_block_nodes(NULL
);
443 for (blockdev
= blockdev_list
; blockdev
; blockdev
= blockdev
->next
) {
444 assert(blockdev
->value
->has_node_name
);
445 if (device
&& strcmp(device
, blockdev
->value
->node_name
)) {
449 if (blockdev
!= blockdev_list
) {
450 monitor_printf(mon
, "\n");
453 print_block_info(mon
, NULL
, blockdev
->value
, verbose
);
455 qapi_free_BlockDeviceInfoList(blockdev_list
);
458 void hmp_info_blockstats(Monitor
*mon
, const QDict
*qdict
)
460 BlockStatsList
*stats_list
, *stats
;
462 stats_list
= qmp_query_blockstats(false, false, NULL
);
464 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
465 if (!stats
->value
->has_device
) {
469 monitor_printf(mon
, "%s:", stats
->value
->device
);
470 monitor_printf(mon
, " rd_bytes=%" PRId64
472 " rd_operations=%" PRId64
473 " wr_operations=%" PRId64
474 " flush_operations=%" PRId64
475 " wr_total_time_ns=%" PRId64
476 " rd_total_time_ns=%" PRId64
477 " flush_total_time_ns=%" PRId64
478 " rd_merged=%" PRId64
479 " wr_merged=%" PRId64
481 stats
->value
->stats
->rd_bytes
,
482 stats
->value
->stats
->wr_bytes
,
483 stats
->value
->stats
->rd_operations
,
484 stats
->value
->stats
->wr_operations
,
485 stats
->value
->stats
->flush_operations
,
486 stats
->value
->stats
->wr_total_time_ns
,
487 stats
->value
->stats
->rd_total_time_ns
,
488 stats
->value
->stats
->flush_total_time_ns
,
489 stats
->value
->stats
->rd_merged
,
490 stats
->value
->stats
->wr_merged
);
493 qapi_free_BlockStatsList(stats_list
);
496 void hmp_info_vnc(Monitor
*mon
, const QDict
*qdict
)
500 VncClientInfoList
*client
;
502 info
= qmp_query_vnc(&err
);
504 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
509 if (!info
->enabled
) {
510 monitor_printf(mon
, "Server: disabled\n");
514 monitor_printf(mon
, "Server:\n");
515 if (info
->has_host
&& info
->has_service
) {
516 monitor_printf(mon
, " address: %s:%s\n", info
->host
, info
->service
);
518 if (info
->has_auth
) {
519 monitor_printf(mon
, " auth: %s\n", info
->auth
);
522 if (!info
->has_clients
|| info
->clients
== NULL
) {
523 monitor_printf(mon
, "Client: none\n");
525 for (client
= info
->clients
; client
; client
= client
->next
) {
526 monitor_printf(mon
, "Client:\n");
527 monitor_printf(mon
, " address: %s:%s\n",
528 client
->value
->base
->host
,
529 client
->value
->base
->service
);
530 monitor_printf(mon
, " x509_dname: %s\n",
531 client
->value
->x509_dname
?
532 client
->value
->x509_dname
: "none");
533 monitor_printf(mon
, " username: %s\n",
534 client
->value
->has_sasl_username
?
535 client
->value
->sasl_username
: "none");
540 qapi_free_VncInfo(info
);
544 void hmp_info_spice(Monitor
*mon
, const QDict
*qdict
)
546 SpiceChannelList
*chan
;
549 info
= qmp_query_spice(NULL
);
551 if (!info
->enabled
) {
552 monitor_printf(mon
, "Server: disabled\n");
556 monitor_printf(mon
, "Server:\n");
557 if (info
->has_port
) {
558 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
559 info
->host
, info
->port
);
561 if (info
->has_tls_port
) {
562 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
563 info
->host
, info
->tls_port
);
565 monitor_printf(mon
, " migrated: %s\n",
566 info
->migrated
? "true" : "false");
567 monitor_printf(mon
, " auth: %s\n", info
->auth
);
568 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
569 monitor_printf(mon
, " mouse-mode: %s\n",
570 SpiceQueryMouseMode_lookup
[info
->mouse_mode
]);
572 if (!info
->has_channels
|| info
->channels
== NULL
) {
573 monitor_printf(mon
, "Channels: none\n");
575 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
576 monitor_printf(mon
, "Channel:\n");
577 monitor_printf(mon
, " address: %s:%s%s\n",
578 chan
->value
->base
->host
, chan
->value
->base
->port
,
579 chan
->value
->tls
? " [tls]" : "");
580 monitor_printf(mon
, " session: %" PRId64
"\n",
581 chan
->value
->connection_id
);
582 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
583 chan
->value
->channel_type
, chan
->value
->channel_id
);
588 qapi_free_SpiceInfo(info
);
592 void hmp_info_balloon(Monitor
*mon
, const QDict
*qdict
)
597 info
= qmp_query_balloon(&err
);
599 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
604 monitor_printf(mon
, "balloon: actual=%" PRId64
"\n", info
->actual
>> 20);
606 qapi_free_BalloonInfo(info
);
609 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
611 PciMemoryRegionList
*region
;
613 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
614 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
615 dev
->slot
, dev
->function
);
616 monitor_printf(mon
, " ");
618 if (dev
->class_info
.has_desc
) {
619 monitor_printf(mon
, "%s", dev
->class_info
.desc
);
621 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
.q_class
);
624 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
625 dev
->id
.vendor
, dev
->id
.device
);
628 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
631 if (dev
->has_pci_bridge
) {
632 monitor_printf(mon
, " BUS %" PRId64
".\n",
633 dev
->pci_bridge
->bus
.number
);
634 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
635 dev
->pci_bridge
->bus
.secondary
);
636 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
637 dev
->pci_bridge
->bus
.subordinate
);
639 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
640 dev
->pci_bridge
->bus
.io_range
->base
,
641 dev
->pci_bridge
->bus
.io_range
->limit
);
644 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
645 dev
->pci_bridge
->bus
.memory_range
->base
,
646 dev
->pci_bridge
->bus
.memory_range
->limit
);
648 monitor_printf(mon
, " prefetchable memory range "
649 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
650 dev
->pci_bridge
->bus
.prefetchable_range
->base
,
651 dev
->pci_bridge
->bus
.prefetchable_range
->limit
);
654 for (region
= dev
->regions
; region
; region
= region
->next
) {
657 addr
= region
->value
->address
;
658 size
= region
->value
->size
;
660 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
662 if (!strcmp(region
->value
->type
, "io")) {
663 monitor_printf(mon
, "I/O at 0x%04" PRIx64
664 " [0x%04" PRIx64
"].\n",
665 addr
, addr
+ size
- 1);
667 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
668 " [0x%08" PRIx64
"].\n",
669 region
->value
->mem_type_64
? 64 : 32,
670 region
->value
->prefetch
? " prefetchable" : "",
671 addr
, addr
+ size
- 1);
675 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
677 if (dev
->has_pci_bridge
) {
678 if (dev
->pci_bridge
->has_devices
) {
679 PciDeviceInfoList
*cdev
;
680 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
681 hmp_info_pci_device(mon
, cdev
->value
);
687 void hmp_info_pci(Monitor
*mon
, const QDict
*qdict
)
689 PciInfoList
*info_list
, *info
;
692 info_list
= qmp_query_pci(&err
);
694 monitor_printf(mon
, "PCI devices not supported\n");
699 for (info
= info_list
; info
; info
= info
->next
) {
700 PciDeviceInfoList
*dev
;
702 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
703 hmp_info_pci_device(mon
, dev
->value
);
707 qapi_free_PciInfoList(info_list
);
710 void hmp_info_block_jobs(Monitor
*mon
, const QDict
*qdict
)
712 BlockJobInfoList
*list
;
715 list
= qmp_query_block_jobs(&err
);
719 monitor_printf(mon
, "No active jobs\n");
724 if (strcmp(list
->value
->type
, "stream") == 0) {
725 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
726 " of %" PRId64
" bytes, speed limit %" PRId64
733 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
734 " of %" PRId64
" bytes, speed limit %" PRId64
745 qapi_free_BlockJobInfoList(list
);
748 void hmp_info_tpm(Monitor
*mon
, const QDict
*qdict
)
750 TPMInfoList
*info_list
, *info
;
753 TPMPassthroughOptions
*tpo
;
755 info_list
= qmp_query_tpm(&err
);
757 monitor_printf(mon
, "TPM device not supported\n");
763 monitor_printf(mon
, "TPM device:\n");
766 for (info
= info_list
; info
; info
= info
->next
) {
767 TPMInfo
*ti
= info
->value
;
768 monitor_printf(mon
, " tpm%d: model=%s\n",
769 c
, TpmModel_lookup
[ti
->model
]);
771 monitor_printf(mon
, " \\ %s: type=%s",
772 ti
->id
, TpmTypeOptionsKind_lookup
[ti
->options
->kind
]);
774 switch (ti
->options
->kind
) {
775 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH
:
776 tpo
= ti
->options
->passthrough
;
777 monitor_printf(mon
, "%s%s%s%s",
778 tpo
->has_path
? ",path=" : "",
779 tpo
->has_path
? tpo
->path
: "",
780 tpo
->has_cancel_path
? ",cancel-path=" : "",
781 tpo
->has_cancel_path
? tpo
->cancel_path
: "");
783 case TPM_TYPE_OPTIONS_KIND_MAX
:
786 monitor_printf(mon
, "\n");
789 qapi_free_TPMInfoList(info_list
);
792 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
794 monitor_suspend(mon
);
798 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
803 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
805 qmp_system_reset(NULL
);
808 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
810 qmp_system_powerdown(NULL
);
813 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
817 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
818 use it are converted to the QAPI */
819 cpu_index
= qdict_get_int(qdict
, "index");
820 if (monitor_set_cpu(cpu_index
) < 0) {
821 monitor_printf(mon
, "invalid CPU index\n");
825 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
827 uint32_t size
= qdict_get_int(qdict
, "size");
828 const char *filename
= qdict_get_str(qdict
, "filename");
829 uint64_t addr
= qdict_get_int(qdict
, "val");
832 qmp_memsave(addr
, size
, filename
, true, monitor_get_cpu_index(), &err
);
833 hmp_handle_error(mon
, &err
);
836 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
838 uint32_t size
= qdict_get_int(qdict
, "size");
839 const char *filename
= qdict_get_str(qdict
, "filename");
840 uint64_t addr
= qdict_get_int(qdict
, "val");
843 qmp_pmemsave(addr
, size
, filename
, &err
);
844 hmp_handle_error(mon
, &err
);
847 void hmp_ringbuf_write(Monitor
*mon
, const QDict
*qdict
)
849 const char *chardev
= qdict_get_str(qdict
, "device");
850 const char *data
= qdict_get_str(qdict
, "data");
853 qmp_ringbuf_write(chardev
, data
, false, 0, &err
);
855 hmp_handle_error(mon
, &err
);
858 void hmp_ringbuf_read(Monitor
*mon
, const QDict
*qdict
)
860 uint32_t size
= qdict_get_int(qdict
, "size");
861 const char *chardev
= qdict_get_str(qdict
, "device");
866 data
= qmp_ringbuf_read(chardev
, size
, false, 0, &err
);
868 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
873 for (i
= 0; data
[i
]; i
++) {
874 unsigned char ch
= data
[i
];
877 monitor_printf(mon
, "\\\\");
878 } else if ((ch
< 0x20 && ch
!= '\n' && ch
!= '\t') || ch
== 0x7F) {
879 monitor_printf(mon
, "\\u%04X", ch
);
881 monitor_printf(mon
, "%c", ch
);
885 monitor_printf(mon
, "\n");
889 static void hmp_cont_cb(void *opaque
, int err
)
896 static bool key_is_missing(const BlockInfo
*bdev
)
898 return (bdev
->inserted
&& bdev
->inserted
->encryption_key_missing
);
901 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
903 BlockInfoList
*bdev_list
, *bdev
;
906 bdev_list
= qmp_query_block(NULL
);
907 for (bdev
= bdev_list
; bdev
; bdev
= bdev
->next
) {
908 if (key_is_missing(bdev
->value
)) {
909 monitor_read_block_device_key(mon
, bdev
->value
->device
,
916 hmp_handle_error(mon
, &err
);
919 qapi_free_BlockInfoList(bdev_list
);
922 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
924 qmp_system_wakeup(NULL
);
927 void hmp_inject_nmi(Monitor
*mon
, const QDict
*qdict
)
931 qmp_inject_nmi(&err
);
932 hmp_handle_error(mon
, &err
);
935 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
937 const char *name
= qdict_get_str(qdict
, "name");
938 int up
= qdict_get_bool(qdict
, "up");
941 qmp_set_link(name
, up
, &err
);
942 hmp_handle_error(mon
, &err
);
945 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
947 const char *device
= qdict_get_str(qdict
, "device");
948 const char *password
= qdict_get_str(qdict
, "password");
951 qmp_block_passwd(true, device
, false, NULL
, password
, &err
);
952 hmp_handle_error(mon
, &err
);
955 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
957 int64_t value
= qdict_get_int(qdict
, "value");
960 qmp_balloon(value
, &err
);
962 monitor_printf(mon
, "balloon: %s\n", error_get_pretty(err
));
967 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
969 const char *device
= qdict_get_str(qdict
, "device");
970 int64_t size
= qdict_get_int(qdict
, "size");
973 qmp_block_resize(true, device
, false, NULL
, size
, &err
);
974 hmp_handle_error(mon
, &err
);
977 void hmp_drive_mirror(Monitor
*mon
, const QDict
*qdict
)
979 const char *device
= qdict_get_str(qdict
, "device");
980 const char *filename
= qdict_get_str(qdict
, "target");
981 const char *format
= qdict_get_try_str(qdict
, "format");
982 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
983 int full
= qdict_get_try_bool(qdict
, "full", 0);
984 enum NewImageMode mode
;
988 error_set(&err
, QERR_MISSING_PARAMETER
, "target");
989 hmp_handle_error(mon
, &err
);
994 mode
= NEW_IMAGE_MODE_EXISTING
;
996 mode
= NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
999 qmp_drive_mirror(device
, filename
, !!format
, format
,
1000 false, NULL
, false, NULL
,
1001 full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1002 true, mode
, false, 0, false, 0, false, 0,
1003 false, 0, false, 0, &err
);
1004 hmp_handle_error(mon
, &err
);
1007 void hmp_drive_backup(Monitor
*mon
, const QDict
*qdict
)
1009 const char *device
= qdict_get_str(qdict
, "device");
1010 const char *filename
= qdict_get_str(qdict
, "target");
1011 const char *format
= qdict_get_try_str(qdict
, "format");
1012 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
1013 int full
= qdict_get_try_bool(qdict
, "full", 0);
1014 enum NewImageMode mode
;
1018 error_set(&err
, QERR_MISSING_PARAMETER
, "target");
1019 hmp_handle_error(mon
, &err
);
1024 mode
= NEW_IMAGE_MODE_EXISTING
;
1026 mode
= NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
1029 qmp_drive_backup(device
, filename
, !!format
, format
,
1030 full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1031 true, mode
, false, 0, false, 0, false, 0, &err
);
1032 hmp_handle_error(mon
, &err
);
1035 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
1037 const char *device
= qdict_get_str(qdict
, "device");
1038 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
1039 const char *format
= qdict_get_try_str(qdict
, "format");
1040 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
1041 enum NewImageMode mode
;
1045 /* In the future, if 'snapshot-file' is not specified, the snapshot
1046 will be taken internally. Today it's actually required. */
1047 error_set(&err
, QERR_MISSING_PARAMETER
, "snapshot-file");
1048 hmp_handle_error(mon
, &err
);
1052 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
1053 qmp_blockdev_snapshot_sync(true, device
, false, NULL
,
1054 filename
, false, NULL
,
1057 hmp_handle_error(mon
, &err
);
1060 void hmp_snapshot_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1062 const char *device
= qdict_get_str(qdict
, "device");
1063 const char *name
= qdict_get_str(qdict
, "name");
1066 qmp_blockdev_snapshot_internal_sync(device
, name
, &err
);
1067 hmp_handle_error(mon
, &err
);
1070 void hmp_snapshot_delete_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1072 const char *device
= qdict_get_str(qdict
, "device");
1073 const char *name
= qdict_get_str(qdict
, "name");
1074 const char *id
= qdict_get_try_str(qdict
, "id");
1077 qmp_blockdev_snapshot_delete_internal_sync(device
, !!id
, id
,
1079 hmp_handle_error(mon
, &err
);
1082 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
1084 qmp_migrate_cancel(NULL
);
1087 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
1089 double value
= qdict_get_double(qdict
, "value");
1090 qmp_migrate_set_downtime(value
, NULL
);
1093 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
1095 int64_t value
= qdict_get_int(qdict
, "value");
1098 qmp_migrate_set_cache_size(value
, &err
);
1100 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
1106 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
1108 int64_t value
= qdict_get_int(qdict
, "value");
1109 qmp_migrate_set_speed(value
, NULL
);
1112 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
1114 const char *cap
= qdict_get_str(qdict
, "capability");
1115 bool state
= qdict_get_bool(qdict
, "state");
1117 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
1120 for (i
= 0; i
< MIGRATION_CAPABILITY_MAX
; i
++) {
1121 if (strcmp(cap
, MigrationCapability_lookup
[i
]) == 0) {
1122 caps
->value
= g_malloc0(sizeof(*caps
->value
));
1123 caps
->value
->capability
= i
;
1124 caps
->value
->state
= state
;
1126 qmp_migrate_set_capabilities(caps
, &err
);
1131 if (i
== MIGRATION_CAPABILITY_MAX
) {
1132 error_set(&err
, QERR_INVALID_PARAMETER
, cap
);
1135 qapi_free_MigrationCapabilityStatusList(caps
);
1138 monitor_printf(mon
, "migrate_set_capability: %s\n",
1139 error_get_pretty(err
));
1144 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
1146 const char *protocol
= qdict_get_str(qdict
, "protocol");
1147 const char *password
= qdict_get_str(qdict
, "password");
1148 const char *connected
= qdict_get_try_str(qdict
, "connected");
1151 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
1152 hmp_handle_error(mon
, &err
);
1155 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
1157 const char *protocol
= qdict_get_str(qdict
, "protocol");
1158 const char *whenstr
= qdict_get_str(qdict
, "time");
1161 qmp_expire_password(protocol
, whenstr
, &err
);
1162 hmp_handle_error(mon
, &err
);
1165 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
1167 int force
= qdict_get_try_bool(qdict
, "force", 0);
1168 const char *device
= qdict_get_str(qdict
, "device");
1171 qmp_eject(device
, true, force
, &err
);
1172 hmp_handle_error(mon
, &err
);
1175 static void hmp_change_read_arg(void *opaque
, const char *password
,
1176 void *readline_opaque
)
1178 qmp_change_vnc_password(password
, NULL
);
1179 monitor_read_command(opaque
, 1);
1182 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
1184 const char *device
= qdict_get_str(qdict
, "device");
1185 const char *target
= qdict_get_str(qdict
, "target");
1186 const char *arg
= qdict_get_try_str(qdict
, "arg");
1189 if (strcmp(device
, "vnc") == 0 &&
1190 (strcmp(target
, "passwd") == 0 ||
1191 strcmp(target
, "password") == 0)) {
1193 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
1198 qmp_change(device
, target
, !!arg
, arg
, &err
);
1200 error_get_class(err
) == ERROR_CLASS_DEVICE_ENCRYPTED
) {
1202 monitor_read_block_device_key(mon
, device
, NULL
, NULL
);
1205 hmp_handle_error(mon
, &err
);
1208 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
1212 qmp_block_set_io_throttle(qdict_get_str(qdict
, "device"),
1213 qdict_get_int(qdict
, "bps"),
1214 qdict_get_int(qdict
, "bps_rd"),
1215 qdict_get_int(qdict
, "bps_wr"),
1216 qdict_get_int(qdict
, "iops"),
1217 qdict_get_int(qdict
, "iops_rd"),
1218 qdict_get_int(qdict
, "iops_wr"),
1219 false, /* no burst max via HMP */
1231 false, /* No default I/O size */
1233 hmp_handle_error(mon
, &err
);
1236 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
1238 Error
*error
= NULL
;
1239 const char *device
= qdict_get_str(qdict
, "device");
1240 const char *base
= qdict_get_try_str(qdict
, "base");
1241 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
1243 qmp_block_stream(device
, base
!= NULL
, base
, false, NULL
,
1244 qdict_haskey(qdict
, "speed"), speed
,
1245 true, BLOCKDEV_ON_ERROR_REPORT
, &error
);
1247 hmp_handle_error(mon
, &error
);
1250 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
1252 Error
*error
= NULL
;
1253 const char *device
= qdict_get_str(qdict
, "device");
1254 int64_t value
= qdict_get_int(qdict
, "speed");
1256 qmp_block_job_set_speed(device
, value
, &error
);
1258 hmp_handle_error(mon
, &error
);
1261 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
1263 Error
*error
= NULL
;
1264 const char *device
= qdict_get_str(qdict
, "device");
1265 bool force
= qdict_get_try_bool(qdict
, "force", 0);
1267 qmp_block_job_cancel(device
, true, force
, &error
);
1269 hmp_handle_error(mon
, &error
);
1272 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
1274 Error
*error
= NULL
;
1275 const char *device
= qdict_get_str(qdict
, "device");
1277 qmp_block_job_pause(device
, &error
);
1279 hmp_handle_error(mon
, &error
);
1282 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
1284 Error
*error
= NULL
;
1285 const char *device
= qdict_get_str(qdict
, "device");
1287 qmp_block_job_resume(device
, &error
);
1289 hmp_handle_error(mon
, &error
);
1292 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
1294 Error
*error
= NULL
;
1295 const char *device
= qdict_get_str(qdict
, "device");
1297 qmp_block_job_complete(device
, &error
);
1299 hmp_handle_error(mon
, &error
);
1302 typedef struct MigrationStatus
1306 bool is_block_migration
;
1309 static void hmp_migrate_status_cb(void *opaque
)
1311 MigrationStatus
*status
= opaque
;
1312 MigrationInfo
*info
;
1314 info
= qmp_query_migrate(NULL
);
1315 if (!info
->has_status
|| strcmp(info
->status
, "active") == 0 ||
1316 strcmp(info
->status
, "setup") == 0) {
1317 if (info
->has_disk
) {
1320 if (info
->disk
->remaining
) {
1321 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1326 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1327 monitor_flush(status
->mon
);
1330 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1000);
1332 if (status
->is_block_migration
) {
1333 monitor_printf(status
->mon
, "\n");
1335 monitor_resume(status
->mon
);
1336 timer_del(status
->timer
);
1340 qapi_free_MigrationInfo(info
);
1343 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1345 int detach
= qdict_get_try_bool(qdict
, "detach", 0);
1346 int blk
= qdict_get_try_bool(qdict
, "blk", 0);
1347 int inc
= qdict_get_try_bool(qdict
, "inc", 0);
1348 const char *uri
= qdict_get_str(qdict
, "uri");
1351 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
1353 monitor_printf(mon
, "migrate: %s\n", error_get_pretty(err
));
1359 MigrationStatus
*status
;
1361 if (monitor_suspend(mon
) < 0) {
1362 monitor_printf(mon
, "terminal does not allow synchronous "
1363 "migration, continuing detached\n");
1367 status
= g_malloc0(sizeof(*status
));
1369 status
->is_block_migration
= blk
|| inc
;
1370 status
->timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, hmp_migrate_status_cb
,
1372 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
1376 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1378 const char *id
= qdict_get_str(qdict
, "id");
1381 qmp_device_del(id
, &err
);
1382 hmp_handle_error(mon
, &err
);
1385 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1388 int paging
= qdict_get_try_bool(qdict
, "paging", 0);
1389 int zlib
= qdict_get_try_bool(qdict
, "zlib", 0);
1390 int lzo
= qdict_get_try_bool(qdict
, "lzo", 0);
1391 int snappy
= qdict_get_try_bool(qdict
, "snappy", 0);
1392 const char *file
= qdict_get_str(qdict
, "filename");
1393 bool has_begin
= qdict_haskey(qdict
, "begin");
1394 bool has_length
= qdict_haskey(qdict
, "length");
1397 enum DumpGuestMemoryFormat dump_format
= DUMP_GUEST_MEMORY_FORMAT_ELF
;
1400 if (zlib
+ lzo
+ snappy
> 1) {
1401 error_setg(&err
, "only one of '-z|-l|-s' can be set");
1402 hmp_handle_error(mon
, &err
);
1407 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB
;
1411 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO
;
1415 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY
;
1419 begin
= qdict_get_int(qdict
, "begin");
1422 length
= qdict_get_int(qdict
, "length");
1425 prot
= g_strconcat("file:", file
, NULL
);
1427 qmp_dump_guest_memory(paging
, prot
, has_begin
, begin
, has_length
, length
,
1428 true, dump_format
, &err
);
1429 hmp_handle_error(mon
, &err
);
1433 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
1438 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
1443 netdev_add(opts
, &err
);
1445 qemu_opts_del(opts
);
1449 hmp_handle_error(mon
, &err
);
1452 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
1454 const char *id
= qdict_get_str(qdict
, "id");
1457 qmp_netdev_del(id
, &err
);
1458 hmp_handle_error(mon
, &err
);
1461 void hmp_object_add(Monitor
*mon
, const QDict
*qdict
)
1464 Error
*err_end
= NULL
;
1472 opts
= qemu_opts_from_qdict(qemu_find_opts("object"), qdict
, &err
);
1477 ov
= opts_visitor_new(opts
);
1478 pdict
= qdict_clone_shallow(qdict
);
1480 visit_start_struct(opts_get_visitor(ov
), &dummy
, NULL
, NULL
, 0, &err
);
1485 qdict_del(pdict
, "qom-type");
1486 visit_type_str(opts_get_visitor(ov
), &type
, "qom-type", &err
);
1491 qdict_del(pdict
, "id");
1492 visit_type_str(opts_get_visitor(ov
), &id
, "id", &err
);
1497 object_add(type
, id
, pdict
, opts_get_visitor(ov
), &err
);
1500 visit_end_struct(opts_get_visitor(ov
), &err_end
);
1501 if (!err
&& err_end
) {
1502 qmp_object_del(id
, NULL
);
1504 error_propagate(&err
, err_end
);
1506 opts_visitor_cleanup(ov
);
1509 qemu_opts_del(opts
);
1515 hmp_handle_error(mon
, &err
);
1518 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
1520 const char *fdname
= qdict_get_str(qdict
, "fdname");
1523 qmp_getfd(fdname
, &err
);
1524 hmp_handle_error(mon
, &err
);
1527 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
1529 const char *fdname
= qdict_get_str(qdict
, "fdname");
1532 qmp_closefd(fdname
, &err
);
1533 hmp_handle_error(mon
, &err
);
1536 void hmp_send_key(Monitor
*mon
, const QDict
*qdict
)
1538 const char *keys
= qdict_get_str(qdict
, "keys");
1539 KeyValueList
*keylist
, *head
= NULL
, *tmp
= NULL
;
1540 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
1541 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
1543 char keyname_buf
[16];
1548 separator
= strchr(keys
, '-');
1549 keyname_len
= separator
? separator
- keys
: strlen(keys
);
1550 pstrcpy(keyname_buf
, sizeof(keyname_buf
), keys
);
1552 /* Be compatible with old interface, convert user inputted "<" */
1553 if (!strncmp(keyname_buf
, "<", 1) && keyname_len
== 1) {
1554 pstrcpy(keyname_buf
, sizeof(keyname_buf
), "less");
1557 keyname_buf
[keyname_len
] = 0;
1559 keylist
= g_malloc0(sizeof(*keylist
));
1560 keylist
->value
= g_malloc0(sizeof(*keylist
->value
));
1566 tmp
->next
= keylist
;
1570 if (strstart(keyname_buf
, "0x", NULL
)) {
1572 int value
= strtoul(keyname_buf
, &endp
, 0);
1573 if (*endp
!= '\0') {
1576 keylist
->value
->kind
= KEY_VALUE_KIND_NUMBER
;
1577 keylist
->value
->number
= value
;
1579 int idx
= index_from_key(keyname_buf
);
1580 if (idx
== Q_KEY_CODE_MAX
) {
1583 keylist
->value
->kind
= KEY_VALUE_KIND_QCODE
;
1584 keylist
->value
->qcode
= idx
;
1590 keys
= separator
+ 1;
1593 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
1594 hmp_handle_error(mon
, &err
);
1597 qapi_free_KeyValueList(head
);
1601 monitor_printf(mon
, "invalid parameter: %s\n", keyname_buf
);
1605 void hmp_screen_dump(Monitor
*mon
, const QDict
*qdict
)
1607 const char *filename
= qdict_get_str(qdict
, "filename");
1610 qmp_screendump(filename
, &err
);
1611 hmp_handle_error(mon
, &err
);
1614 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
1616 const char *uri
= qdict_get_str(qdict
, "uri");
1617 int writable
= qdict_get_try_bool(qdict
, "writable", 0);
1618 int all
= qdict_get_try_bool(qdict
, "all", 0);
1619 Error
*local_err
= NULL
;
1620 BlockInfoList
*block_list
, *info
;
1621 SocketAddress
*addr
;
1623 if (writable
&& !all
) {
1624 error_setg(&local_err
, "-w only valid together with -a");
1628 /* First check if the address is valid and start the server. */
1629 addr
= socket_parse(uri
, &local_err
);
1630 if (local_err
!= NULL
) {
1634 qmp_nbd_server_start(addr
, &local_err
);
1635 qapi_free_SocketAddress(addr
);
1636 if (local_err
!= NULL
) {
1644 /* Then try adding all block devices. If one fails, close all and
1647 block_list
= qmp_query_block(NULL
);
1649 for (info
= block_list
; info
; info
= info
->next
) {
1650 if (!info
->value
->has_inserted
) {
1654 qmp_nbd_server_add(info
->value
->device
, true, writable
, &local_err
);
1656 if (local_err
!= NULL
) {
1657 qmp_nbd_server_stop(NULL
);
1662 qapi_free_BlockInfoList(block_list
);
1665 hmp_handle_error(mon
, &local_err
);
1668 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
1670 const char *device
= qdict_get_str(qdict
, "device");
1671 int writable
= qdict_get_try_bool(qdict
, "writable", 0);
1672 Error
*local_err
= NULL
;
1674 qmp_nbd_server_add(device
, true, writable
, &local_err
);
1676 if (local_err
!= NULL
) {
1677 hmp_handle_error(mon
, &local_err
);
1681 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
1685 qmp_nbd_server_stop(&err
);
1686 hmp_handle_error(mon
, &err
);
1689 void hmp_cpu_add(Monitor
*mon
, const QDict
*qdict
)
1694 cpuid
= qdict_get_int(qdict
, "id");
1695 qmp_cpu_add(cpuid
, &err
);
1696 hmp_handle_error(mon
, &err
);
1699 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
1701 const char *args
= qdict_get_str(qdict
, "args");
1705 opts
= qemu_opts_parse(qemu_find_opts("chardev"), args
, 1);
1707 error_setg(&err
, "Parsing chardev args failed");
1709 qemu_chr_new_from_opts(opts
, NULL
, &err
);
1711 hmp_handle_error(mon
, &err
);
1714 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
1716 Error
*local_err
= NULL
;
1718 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
1719 hmp_handle_error(mon
, &local_err
);
1722 void hmp_qemu_io(Monitor
*mon
, const QDict
*qdict
)
1725 const char* device
= qdict_get_str(qdict
, "device");
1726 const char* command
= qdict_get_str(qdict
, "command");
1729 blk
= blk_by_name(device
);
1731 qemuio_command(blk
, command
);
1733 error_set(&err
, QERR_DEVICE_NOT_FOUND
, device
);
1736 hmp_handle_error(mon
, &err
);
1739 void hmp_object_del(Monitor
*mon
, const QDict
*qdict
)
1741 const char *id
= qdict_get_str(qdict
, "id");
1744 qmp_object_del(id
, &err
);
1745 hmp_handle_error(mon
, &err
);
1748 void hmp_info_memdev(Monitor
*mon
, const QDict
*qdict
)
1751 MemdevList
*memdev_list
= qmp_query_memdev(&err
);
1752 MemdevList
*m
= memdev_list
;
1753 StringOutputVisitor
*ov
;
1759 ov
= string_output_visitor_new(false);
1760 visit_type_uint16List(string_output_get_visitor(ov
),
1761 &m
->value
->host_nodes
, NULL
, NULL
);
1762 monitor_printf(mon
, "memory backend: %d\n", i
);
1763 monitor_printf(mon
, " size: %" PRId64
"\n", m
->value
->size
);
1764 monitor_printf(mon
, " merge: %s\n",
1765 m
->value
->merge
? "true" : "false");
1766 monitor_printf(mon
, " dump: %s\n",
1767 m
->value
->dump
? "true" : "false");
1768 monitor_printf(mon
, " prealloc: %s\n",
1769 m
->value
->prealloc
? "true" : "false");
1770 monitor_printf(mon
, " policy: %s\n",
1771 HostMemPolicy_lookup
[m
->value
->policy
]);
1772 str
= string_output_get_string(ov
);
1773 monitor_printf(mon
, " host nodes: %s\n", str
);
1776 string_output_visitor_cleanup(ov
);
1781 monitor_printf(mon
, "\n");
1783 qapi_free_MemdevList(memdev_list
);
1786 void hmp_info_memory_devices(Monitor
*mon
, const QDict
*qdict
)
1789 MemoryDeviceInfoList
*info_list
= qmp_query_memory_devices(&err
);
1790 MemoryDeviceInfoList
*info
;
1791 MemoryDeviceInfo
*value
;
1792 PCDIMMDeviceInfo
*di
;
1794 for (info
= info_list
; info
; info
= info
->next
) {
1795 value
= info
->value
;
1798 switch (value
->kind
) {
1799 case MEMORY_DEVICE_INFO_KIND_DIMM
:
1802 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
1803 MemoryDeviceInfoKind_lookup
[value
->kind
],
1804 di
->id
? di
->id
: "");
1805 monitor_printf(mon
, " addr: 0x%" PRIx64
"\n", di
->addr
);
1806 monitor_printf(mon
, " slot: %" PRId64
"\n", di
->slot
);
1807 monitor_printf(mon
, " node: %" PRId64
"\n", di
->node
);
1808 monitor_printf(mon
, " size: %" PRIu64
"\n", di
->size
);
1809 monitor_printf(mon
, " memdev: %s\n", di
->memdev
);
1810 monitor_printf(mon
, " hotplugged: %s\n",
1811 di
->hotplugged
? "true" : "false");
1812 monitor_printf(mon
, " hotpluggable: %s\n",
1813 di
->hotpluggable
? "true" : "false");
1821 qapi_free_MemoryDeviceInfoList(info_list
);