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 "qemu/option.h"
20 #include "qemu/timer.h"
21 #include "qmp-commands.h"
22 #include "qemu/sockets.h"
23 #include "monitor/monitor.h"
24 #include "qapi/opts-visitor.h"
25 #include "qapi/string-output-visitor.h"
26 #include "qapi-visit.h"
27 #include "ui/console.h"
28 #include "block/qapi.h"
31 static void hmp_handle_error(Monitor
*mon
, Error
**errp
)
35 monitor_printf(mon
, "%s\n", error_get_pretty(*errp
));
40 void hmp_info_name(Monitor
*mon
, const QDict
*qdict
)
44 info
= qmp_query_name(NULL
);
46 monitor_printf(mon
, "%s\n", info
->name
);
48 qapi_free_NameInfo(info
);
51 void hmp_info_version(Monitor
*mon
, const QDict
*qdict
)
55 info
= qmp_query_version(NULL
);
57 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
58 info
->qemu
.major
, info
->qemu
.minor
, info
->qemu
.micro
,
61 qapi_free_VersionInfo(info
);
64 void hmp_info_kvm(Monitor
*mon
, const QDict
*qdict
)
68 info
= qmp_query_kvm(NULL
);
69 monitor_printf(mon
, "kvm support: ");
71 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
73 monitor_printf(mon
, "not compiled\n");
76 qapi_free_KvmInfo(info
);
79 void hmp_info_status(Monitor
*mon
, const QDict
*qdict
)
83 info
= qmp_query_status(NULL
);
85 monitor_printf(mon
, "VM status: %s%s",
86 info
->running
? "running" : "paused",
87 info
->singlestep
? " (single step mode)" : "");
89 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
90 monitor_printf(mon
, " (%s)", RunState_lookup
[info
->status
]);
93 monitor_printf(mon
, "\n");
95 qapi_free_StatusInfo(info
);
98 void hmp_info_uuid(Monitor
*mon
, const QDict
*qdict
)
102 info
= qmp_query_uuid(NULL
);
103 monitor_printf(mon
, "%s\n", info
->UUID
);
104 qapi_free_UuidInfo(info
);
107 void hmp_info_chardev(Monitor
*mon
, const QDict
*qdict
)
109 ChardevInfoList
*char_info
, *info
;
111 char_info
= qmp_query_chardev(NULL
);
112 for (info
= char_info
; info
; info
= info
->next
) {
113 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
114 info
->value
->filename
);
117 qapi_free_ChardevInfoList(char_info
);
120 void hmp_info_mice(Monitor
*mon
, const QDict
*qdict
)
122 MouseInfoList
*mice_list
, *mouse
;
124 mice_list
= qmp_query_mice(NULL
);
126 monitor_printf(mon
, "No mouse devices connected\n");
130 for (mouse
= mice_list
; mouse
; mouse
= mouse
->next
) {
131 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s%s\n",
132 mouse
->value
->current
? '*' : ' ',
133 mouse
->value
->index
, mouse
->value
->name
,
134 mouse
->value
->absolute
? " (absolute)" : "");
137 qapi_free_MouseInfoList(mice_list
);
140 void hmp_info_migrate(Monitor
*mon
, const QDict
*qdict
)
143 MigrationCapabilityStatusList
*caps
, *cap
;
145 info
= qmp_query_migrate(NULL
);
146 caps
= qmp_query_migrate_capabilities(NULL
);
148 /* do not display parameters during setup */
149 if (info
->has_status
&& caps
) {
150 monitor_printf(mon
, "capabilities: ");
151 for (cap
= caps
; cap
; cap
= cap
->next
) {
152 monitor_printf(mon
, "%s: %s ",
153 MigrationCapability_lookup
[cap
->value
->capability
],
154 cap
->value
->state
? "on" : "off");
156 monitor_printf(mon
, "\n");
159 if (info
->has_status
) {
160 monitor_printf(mon
, "Migration status: %s\n", info
->status
);
161 monitor_printf(mon
, "total time: %" PRIu64
" milliseconds\n",
163 if (info
->has_expected_downtime
) {
164 monitor_printf(mon
, "expected downtime: %" PRIu64
" milliseconds\n",
165 info
->expected_downtime
);
167 if (info
->has_downtime
) {
168 monitor_printf(mon
, "downtime: %" PRIu64
" milliseconds\n",
171 if (info
->has_setup_time
) {
172 monitor_printf(mon
, "setup: %" PRIu64
" milliseconds\n",
178 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
179 info
->ram
->transferred
>> 10);
180 monitor_printf(mon
, "throughput: %0.2f mbps\n",
182 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
183 info
->ram
->remaining
>> 10);
184 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
185 info
->ram
->total
>> 10);
186 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
187 info
->ram
->duplicate
);
188 monitor_printf(mon
, "skipped: %" PRIu64
" pages\n",
190 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
192 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
193 info
->ram
->normal_bytes
>> 10);
194 monitor_printf(mon
, "dirty sync count: %" PRIu64
"\n",
195 info
->ram
->dirty_sync_count
);
196 if (info
->ram
->dirty_pages_rate
) {
197 monitor_printf(mon
, "dirty pages rate: %" PRIu64
" pages\n",
198 info
->ram
->dirty_pages_rate
);
202 if (info
->has_disk
) {
203 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
204 info
->disk
->transferred
>> 10);
205 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
206 info
->disk
->remaining
>> 10);
207 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
208 info
->disk
->total
>> 10);
211 if (info
->has_xbzrle_cache
) {
212 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
213 info
->xbzrle_cache
->cache_size
);
214 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
215 info
->xbzrle_cache
->bytes
>> 10);
216 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
217 info
->xbzrle_cache
->pages
);
218 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
"\n",
219 info
->xbzrle_cache
->cache_miss
);
220 monitor_printf(mon
, "xbzrle cache miss rate: %0.2f\n",
221 info
->xbzrle_cache
->cache_miss_rate
);
222 monitor_printf(mon
, "xbzrle overflow : %" PRIu64
"\n",
223 info
->xbzrle_cache
->overflow
);
226 qapi_free_MigrationInfo(info
);
227 qapi_free_MigrationCapabilityStatusList(caps
);
230 void hmp_info_migrate_capabilities(Monitor
*mon
, const QDict
*qdict
)
232 MigrationCapabilityStatusList
*caps
, *cap
;
234 caps
= qmp_query_migrate_capabilities(NULL
);
237 monitor_printf(mon
, "capabilities: ");
238 for (cap
= caps
; cap
; cap
= cap
->next
) {
239 monitor_printf(mon
, "%s: %s ",
240 MigrationCapability_lookup
[cap
->value
->capability
],
241 cap
->value
->state
? "on" : "off");
243 monitor_printf(mon
, "\n");
246 qapi_free_MigrationCapabilityStatusList(caps
);
249 void hmp_info_migrate_cache_size(Monitor
*mon
, const QDict
*qdict
)
251 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
252 qmp_query_migrate_cache_size(NULL
) >> 10);
255 void hmp_info_cpus(Monitor
*mon
, const QDict
*qdict
)
257 CpuInfoList
*cpu_list
, *cpu
;
259 cpu_list
= qmp_query_cpus(NULL
);
261 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
264 if (cpu
->value
->CPU
== monitor_get_cpu_index()) {
268 monitor_printf(mon
, "%c CPU #%" PRId64
":", active
, cpu
->value
->CPU
);
270 if (cpu
->value
->has_pc
) {
271 monitor_printf(mon
, " pc=0x%016" PRIx64
, cpu
->value
->pc
);
273 if (cpu
->value
->has_nip
) {
274 monitor_printf(mon
, " nip=0x%016" PRIx64
, cpu
->value
->nip
);
276 if (cpu
->value
->has_npc
) {
277 monitor_printf(mon
, " npc=0x%016" PRIx64
, cpu
->value
->npc
);
279 if (cpu
->value
->has_PC
) {
280 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->PC
);
283 if (cpu
->value
->halted
) {
284 monitor_printf(mon
, " (halted)");
287 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
290 qapi_free_CpuInfoList(cpu_list
);
293 static void print_block_info(Monitor
*mon
, BlockInfo
*info
,
294 BlockDeviceInfo
*inserted
, bool verbose
)
296 ImageInfo
*image_info
;
298 monitor_printf(mon
, "%s", info
->device
);
300 monitor_printf(mon
, ": %s (%s%s%s)\n",
303 inserted
->ro
? ", read-only" : "",
304 inserted
->encrypted
? ", encrypted" : "");
306 monitor_printf(mon
, ": [not inserted]\n");
309 if (info
->has_io_status
&& info
->io_status
!= BLOCK_DEVICE_IO_STATUS_OK
) {
310 monitor_printf(mon
, " I/O status: %s\n",
311 BlockDeviceIoStatus_lookup
[info
->io_status
]);
314 if (info
->removable
) {
315 monitor_printf(mon
, " Removable device: %slocked, tray %s\n",
316 info
->locked
? "" : "not ",
317 info
->tray_open
? "open" : "closed");
325 monitor_printf(mon
, " Cache mode: %s%s%s\n",
326 inserted
->cache
->writeback
? "writeback" : "writethrough",
327 inserted
->cache
->direct
? ", direct" : "",
328 inserted
->cache
->no_flush
? ", ignore flushes" : "");
330 if (inserted
->has_backing_file
) {
333 "(chain depth: %" PRId64
")\n",
334 inserted
->backing_file
,
335 inserted
->backing_file_depth
);
338 if (inserted
->detect_zeroes
!= BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF
) {
339 monitor_printf(mon
, " Detect zeroes: %s\n",
340 BlockdevDetectZeroesOptions_lookup
[inserted
->detect_zeroes
]);
343 if (inserted
->bps
|| inserted
->bps_rd
|| inserted
->bps_wr
||
344 inserted
->iops
|| inserted
->iops_rd
|| inserted
->iops_wr
)
346 monitor_printf(mon
, " I/O throttling: bps=%" PRId64
347 " bps_rd=%" PRId64
" bps_wr=%" PRId64
349 " bps_rd_max=%" PRId64
350 " bps_wr_max=%" PRId64
351 " iops=%" PRId64
" iops_rd=%" PRId64
354 " iops_rd_max=%" PRId64
355 " iops_wr_max=%" PRId64
356 " iops_size=%" PRId64
"\n",
361 inserted
->bps_rd_max
,
362 inserted
->bps_wr_max
,
367 inserted
->iops_rd_max
,
368 inserted
->iops_wr_max
,
369 inserted
->iops_size
);
373 monitor_printf(mon
, "\nImages:\n");
374 image_info
= inserted
->image
;
376 bdrv_image_info_dump((fprintf_function
)monitor_printf
,
378 if (image_info
->has_backing_image
) {
379 image_info
= image_info
->backing_image
;
387 void hmp_info_block(Monitor
*mon
, const QDict
*qdict
)
389 BlockInfoList
*block_list
, *info
;
390 const char *device
= qdict_get_try_str(qdict
, "device");
391 bool verbose
= qdict_get_try_bool(qdict
, "verbose", 0);
393 block_list
= qmp_query_block(false);
395 for (info
= block_list
; info
; info
= info
->next
) {
396 if (device
&& strcmp(device
, info
->value
->device
)) {
400 if (info
!= block_list
) {
401 monitor_printf(mon
, "\n");
404 print_block_info(mon
, info
->value
, info
->value
->has_inserted
405 ? info
->value
->inserted
: NULL
,
409 qapi_free_BlockInfoList(block_list
);
412 void hmp_info_blockstats(Monitor
*mon
, const QDict
*qdict
)
414 BlockStatsList
*stats_list
, *stats
;
416 stats_list
= qmp_query_blockstats(false, false, NULL
);
418 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
419 if (!stats
->value
->has_device
) {
423 monitor_printf(mon
, "%s:", stats
->value
->device
);
424 monitor_printf(mon
, " rd_bytes=%" PRId64
426 " rd_operations=%" PRId64
427 " wr_operations=%" PRId64
428 " flush_operations=%" PRId64
429 " wr_total_time_ns=%" PRId64
430 " rd_total_time_ns=%" PRId64
431 " flush_total_time_ns=%" PRId64
433 stats
->value
->stats
->rd_bytes
,
434 stats
->value
->stats
->wr_bytes
,
435 stats
->value
->stats
->rd_operations
,
436 stats
->value
->stats
->wr_operations
,
437 stats
->value
->stats
->flush_operations
,
438 stats
->value
->stats
->wr_total_time_ns
,
439 stats
->value
->stats
->rd_total_time_ns
,
440 stats
->value
->stats
->flush_total_time_ns
);
443 qapi_free_BlockStatsList(stats_list
);
446 void hmp_info_vnc(Monitor
*mon
, const QDict
*qdict
)
450 VncClientInfoList
*client
;
452 info
= qmp_query_vnc(&err
);
454 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
459 if (!info
->enabled
) {
460 monitor_printf(mon
, "Server: disabled\n");
464 monitor_printf(mon
, "Server:\n");
465 if (info
->has_host
&& info
->has_service
) {
466 monitor_printf(mon
, " address: %s:%s\n", info
->host
, info
->service
);
468 if (info
->has_auth
) {
469 monitor_printf(mon
, " auth: %s\n", info
->auth
);
472 if (!info
->has_clients
|| info
->clients
== NULL
) {
473 monitor_printf(mon
, "Client: none\n");
475 for (client
= info
->clients
; client
; client
= client
->next
) {
476 monitor_printf(mon
, "Client:\n");
477 monitor_printf(mon
, " address: %s:%s\n",
478 client
->value
->base
->host
,
479 client
->value
->base
->service
);
480 monitor_printf(mon
, " x509_dname: %s\n",
481 client
->value
->x509_dname
?
482 client
->value
->x509_dname
: "none");
483 monitor_printf(mon
, " username: %s\n",
484 client
->value
->has_sasl_username
?
485 client
->value
->sasl_username
: "none");
490 qapi_free_VncInfo(info
);
493 void hmp_info_spice(Monitor
*mon
, const QDict
*qdict
)
495 SpiceChannelList
*chan
;
498 info
= qmp_query_spice(NULL
);
500 if (!info
->enabled
) {
501 monitor_printf(mon
, "Server: disabled\n");
505 monitor_printf(mon
, "Server:\n");
506 if (info
->has_port
) {
507 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
508 info
->host
, info
->port
);
510 if (info
->has_tls_port
) {
511 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
512 info
->host
, info
->tls_port
);
514 monitor_printf(mon
, " migrated: %s\n",
515 info
->migrated
? "true" : "false");
516 monitor_printf(mon
, " auth: %s\n", info
->auth
);
517 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
518 monitor_printf(mon
, " mouse-mode: %s\n",
519 SpiceQueryMouseMode_lookup
[info
->mouse_mode
]);
521 if (!info
->has_channels
|| info
->channels
== NULL
) {
522 monitor_printf(mon
, "Channels: none\n");
524 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
525 monitor_printf(mon
, "Channel:\n");
526 monitor_printf(mon
, " address: %s:%s%s\n",
527 chan
->value
->base
->host
, chan
->value
->base
->port
,
528 chan
->value
->tls
? " [tls]" : "");
529 monitor_printf(mon
, " session: %" PRId64
"\n",
530 chan
->value
->connection_id
);
531 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
532 chan
->value
->channel_type
, chan
->value
->channel_id
);
537 qapi_free_SpiceInfo(info
);
540 void hmp_info_balloon(Monitor
*mon
, const QDict
*qdict
)
545 info
= qmp_query_balloon(&err
);
547 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
552 monitor_printf(mon
, "balloon: actual=%" PRId64
"\n", info
->actual
>> 20);
554 qapi_free_BalloonInfo(info
);
557 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
559 PciMemoryRegionList
*region
;
561 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
562 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
563 dev
->slot
, dev
->function
);
564 monitor_printf(mon
, " ");
566 if (dev
->class_info
.has_desc
) {
567 monitor_printf(mon
, "%s", dev
->class_info
.desc
);
569 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
.q_class
);
572 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
573 dev
->id
.vendor
, dev
->id
.device
);
576 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
579 if (dev
->has_pci_bridge
) {
580 monitor_printf(mon
, " BUS %" PRId64
".\n",
581 dev
->pci_bridge
->bus
.number
);
582 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
583 dev
->pci_bridge
->bus
.secondary
);
584 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
585 dev
->pci_bridge
->bus
.subordinate
);
587 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
588 dev
->pci_bridge
->bus
.io_range
->base
,
589 dev
->pci_bridge
->bus
.io_range
->limit
);
592 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
593 dev
->pci_bridge
->bus
.memory_range
->base
,
594 dev
->pci_bridge
->bus
.memory_range
->limit
);
596 monitor_printf(mon
, " prefetchable memory range "
597 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
598 dev
->pci_bridge
->bus
.prefetchable_range
->base
,
599 dev
->pci_bridge
->bus
.prefetchable_range
->limit
);
602 for (region
= dev
->regions
; region
; region
= region
->next
) {
605 addr
= region
->value
->address
;
606 size
= region
->value
->size
;
608 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
610 if (!strcmp(region
->value
->type
, "io")) {
611 monitor_printf(mon
, "I/O at 0x%04" PRIx64
612 " [0x%04" PRIx64
"].\n",
613 addr
, addr
+ size
- 1);
615 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
616 " [0x%08" PRIx64
"].\n",
617 region
->value
->mem_type_64
? 64 : 32,
618 region
->value
->prefetch
? " prefetchable" : "",
619 addr
, addr
+ size
- 1);
623 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
625 if (dev
->has_pci_bridge
) {
626 if (dev
->pci_bridge
->has_devices
) {
627 PciDeviceInfoList
*cdev
;
628 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
629 hmp_info_pci_device(mon
, cdev
->value
);
635 void hmp_info_pci(Monitor
*mon
, const QDict
*qdict
)
637 PciInfoList
*info_list
, *info
;
640 info_list
= qmp_query_pci(&err
);
642 monitor_printf(mon
, "PCI devices not supported\n");
647 for (info
= info_list
; info
; info
= info
->next
) {
648 PciDeviceInfoList
*dev
;
650 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
651 hmp_info_pci_device(mon
, dev
->value
);
655 qapi_free_PciInfoList(info_list
);
658 void hmp_info_block_jobs(Monitor
*mon
, const QDict
*qdict
)
660 BlockJobInfoList
*list
;
663 list
= qmp_query_block_jobs(&err
);
667 monitor_printf(mon
, "No active jobs\n");
672 if (strcmp(list
->value
->type
, "stream") == 0) {
673 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
674 " of %" PRId64
" bytes, speed limit %" PRId64
681 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
682 " of %" PRId64
" bytes, speed limit %" PRId64
693 qapi_free_BlockJobInfoList(list
);
696 void hmp_info_tpm(Monitor
*mon
, const QDict
*qdict
)
698 TPMInfoList
*info_list
, *info
;
701 TPMPassthroughOptions
*tpo
;
703 info_list
= qmp_query_tpm(&err
);
705 monitor_printf(mon
, "TPM device not supported\n");
711 monitor_printf(mon
, "TPM device:\n");
714 for (info
= info_list
; info
; info
= info
->next
) {
715 TPMInfo
*ti
= info
->value
;
716 monitor_printf(mon
, " tpm%d: model=%s\n",
717 c
, TpmModel_lookup
[ti
->model
]);
719 monitor_printf(mon
, " \\ %s: type=%s",
720 ti
->id
, TpmTypeOptionsKind_lookup
[ti
->options
->kind
]);
722 switch (ti
->options
->kind
) {
723 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH
:
724 tpo
= ti
->options
->passthrough
;
725 monitor_printf(mon
, "%s%s%s%s",
726 tpo
->has_path
? ",path=" : "",
727 tpo
->has_path
? tpo
->path
: "",
728 tpo
->has_cancel_path
? ",cancel-path=" : "",
729 tpo
->has_cancel_path
? tpo
->cancel_path
: "");
731 case TPM_TYPE_OPTIONS_KIND_MAX
:
734 monitor_printf(mon
, "\n");
737 qapi_free_TPMInfoList(info_list
);
740 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
742 monitor_suspend(mon
);
746 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
751 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
753 qmp_system_reset(NULL
);
756 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
758 qmp_system_powerdown(NULL
);
761 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
765 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
766 use it are converted to the QAPI */
767 cpu_index
= qdict_get_int(qdict
, "index");
768 if (monitor_set_cpu(cpu_index
) < 0) {
769 monitor_printf(mon
, "invalid CPU index\n");
773 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
775 uint32_t size
= qdict_get_int(qdict
, "size");
776 const char *filename
= qdict_get_str(qdict
, "filename");
777 uint64_t addr
= qdict_get_int(qdict
, "val");
780 qmp_memsave(addr
, size
, filename
, true, monitor_get_cpu_index(), &err
);
781 hmp_handle_error(mon
, &err
);
784 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
786 uint32_t size
= qdict_get_int(qdict
, "size");
787 const char *filename
= qdict_get_str(qdict
, "filename");
788 uint64_t addr
= qdict_get_int(qdict
, "val");
791 qmp_pmemsave(addr
, size
, filename
, &err
);
792 hmp_handle_error(mon
, &err
);
795 void hmp_ringbuf_write(Monitor
*mon
, const QDict
*qdict
)
797 const char *chardev
= qdict_get_str(qdict
, "device");
798 const char *data
= qdict_get_str(qdict
, "data");
801 qmp_ringbuf_write(chardev
, data
, false, 0, &err
);
803 hmp_handle_error(mon
, &err
);
806 void hmp_ringbuf_read(Monitor
*mon
, const QDict
*qdict
)
808 uint32_t size
= qdict_get_int(qdict
, "size");
809 const char *chardev
= qdict_get_str(qdict
, "device");
814 data
= qmp_ringbuf_read(chardev
, size
, false, 0, &err
);
816 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
821 for (i
= 0; data
[i
]; i
++) {
822 unsigned char ch
= data
[i
];
825 monitor_printf(mon
, "\\\\");
826 } else if ((ch
< 0x20 && ch
!= '\n' && ch
!= '\t') || ch
== 0x7F) {
827 monitor_printf(mon
, "\\u%04X", ch
);
829 monitor_printf(mon
, "%c", ch
);
833 monitor_printf(mon
, "\n");
837 static void hmp_cont_cb(void *opaque
, int err
)
844 static bool key_is_missing(const BlockInfo
*bdev
)
846 return (bdev
->inserted
&& bdev
->inserted
->encryption_key_missing
);
849 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
851 BlockInfoList
*bdev_list
, *bdev
;
854 bdev_list
= qmp_query_block(NULL
);
855 for (bdev
= bdev_list
; bdev
; bdev
= bdev
->next
) {
856 if (key_is_missing(bdev
->value
)) {
857 monitor_read_block_device_key(mon
, bdev
->value
->device
,
864 hmp_handle_error(mon
, &err
);
867 qapi_free_BlockInfoList(bdev_list
);
870 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
872 qmp_system_wakeup(NULL
);
875 void hmp_inject_nmi(Monitor
*mon
, const QDict
*qdict
)
879 qmp_inject_nmi(&err
);
880 hmp_handle_error(mon
, &err
);
883 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
885 const char *name
= qdict_get_str(qdict
, "name");
886 int up
= qdict_get_bool(qdict
, "up");
889 qmp_set_link(name
, up
, &err
);
890 hmp_handle_error(mon
, &err
);
893 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
895 const char *device
= qdict_get_str(qdict
, "device");
896 const char *password
= qdict_get_str(qdict
, "password");
899 qmp_block_passwd(true, device
, false, NULL
, password
, &err
);
900 hmp_handle_error(mon
, &err
);
903 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
905 int64_t value
= qdict_get_int(qdict
, "value");
908 qmp_balloon(value
, &err
);
910 monitor_printf(mon
, "balloon: %s\n", error_get_pretty(err
));
915 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
917 const char *device
= qdict_get_str(qdict
, "device");
918 int64_t size
= qdict_get_int(qdict
, "size");
921 qmp_block_resize(true, device
, false, NULL
, size
, &err
);
922 hmp_handle_error(mon
, &err
);
925 void hmp_drive_mirror(Monitor
*mon
, const QDict
*qdict
)
927 const char *device
= qdict_get_str(qdict
, "device");
928 const char *filename
= qdict_get_str(qdict
, "target");
929 const char *format
= qdict_get_try_str(qdict
, "format");
930 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
931 int full
= qdict_get_try_bool(qdict
, "full", 0);
932 enum NewImageMode mode
;
936 error_set(&err
, QERR_MISSING_PARAMETER
, "target");
937 hmp_handle_error(mon
, &err
);
942 mode
= NEW_IMAGE_MODE_EXISTING
;
944 mode
= NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
947 qmp_drive_mirror(device
, filename
, !!format
, format
,
948 false, NULL
, false, NULL
,
949 full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
950 true, mode
, false, 0, false, 0, false, 0,
951 false, 0, false, 0, &err
);
952 hmp_handle_error(mon
, &err
);
955 void hmp_drive_backup(Monitor
*mon
, const QDict
*qdict
)
957 const char *device
= qdict_get_str(qdict
, "device");
958 const char *filename
= qdict_get_str(qdict
, "target");
959 const char *format
= qdict_get_try_str(qdict
, "format");
960 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
961 int full
= qdict_get_try_bool(qdict
, "full", 0);
962 enum NewImageMode mode
;
966 error_set(&err
, QERR_MISSING_PARAMETER
, "target");
967 hmp_handle_error(mon
, &err
);
972 mode
= NEW_IMAGE_MODE_EXISTING
;
974 mode
= NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
977 qmp_drive_backup(device
, filename
, !!format
, format
,
978 full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
979 true, mode
, false, 0, false, 0, false, 0, &err
);
980 hmp_handle_error(mon
, &err
);
983 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
985 const char *device
= qdict_get_str(qdict
, "device");
986 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
987 const char *format
= qdict_get_try_str(qdict
, "format");
988 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
989 enum NewImageMode mode
;
993 /* In the future, if 'snapshot-file' is not specified, the snapshot
994 will be taken internally. Today it's actually required. */
995 error_set(&err
, QERR_MISSING_PARAMETER
, "snapshot-file");
996 hmp_handle_error(mon
, &err
);
1000 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
1001 qmp_blockdev_snapshot_sync(true, device
, false, NULL
,
1002 filename
, false, NULL
,
1005 hmp_handle_error(mon
, &err
);
1008 void hmp_snapshot_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1010 const char *device
= qdict_get_str(qdict
, "device");
1011 const char *name
= qdict_get_str(qdict
, "name");
1014 qmp_blockdev_snapshot_internal_sync(device
, name
, &err
);
1015 hmp_handle_error(mon
, &err
);
1018 void hmp_snapshot_delete_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1020 const char *device
= qdict_get_str(qdict
, "device");
1021 const char *name
= qdict_get_str(qdict
, "name");
1022 const char *id
= qdict_get_try_str(qdict
, "id");
1025 qmp_blockdev_snapshot_delete_internal_sync(device
, !!id
, id
,
1027 hmp_handle_error(mon
, &err
);
1030 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
1032 qmp_migrate_cancel(NULL
);
1035 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
1037 double value
= qdict_get_double(qdict
, "value");
1038 qmp_migrate_set_downtime(value
, NULL
);
1041 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
1043 int64_t value
= qdict_get_int(qdict
, "value");
1046 qmp_migrate_set_cache_size(value
, &err
);
1048 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
1054 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
1056 int64_t value
= qdict_get_int(qdict
, "value");
1057 qmp_migrate_set_speed(value
, NULL
);
1060 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
1062 const char *cap
= qdict_get_str(qdict
, "capability");
1063 bool state
= qdict_get_bool(qdict
, "state");
1065 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
1068 for (i
= 0; i
< MIGRATION_CAPABILITY_MAX
; i
++) {
1069 if (strcmp(cap
, MigrationCapability_lookup
[i
]) == 0) {
1070 caps
->value
= g_malloc0(sizeof(*caps
->value
));
1071 caps
->value
->capability
= i
;
1072 caps
->value
->state
= state
;
1074 qmp_migrate_set_capabilities(caps
, &err
);
1079 if (i
== MIGRATION_CAPABILITY_MAX
) {
1080 error_set(&err
, QERR_INVALID_PARAMETER
, cap
);
1083 qapi_free_MigrationCapabilityStatusList(caps
);
1086 monitor_printf(mon
, "migrate_set_capability: %s\n",
1087 error_get_pretty(err
));
1092 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
1094 const char *protocol
= qdict_get_str(qdict
, "protocol");
1095 const char *password
= qdict_get_str(qdict
, "password");
1096 const char *connected
= qdict_get_try_str(qdict
, "connected");
1099 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
1100 hmp_handle_error(mon
, &err
);
1103 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
1105 const char *protocol
= qdict_get_str(qdict
, "protocol");
1106 const char *whenstr
= qdict_get_str(qdict
, "time");
1109 qmp_expire_password(protocol
, whenstr
, &err
);
1110 hmp_handle_error(mon
, &err
);
1113 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
1115 int force
= qdict_get_try_bool(qdict
, "force", 0);
1116 const char *device
= qdict_get_str(qdict
, "device");
1119 qmp_eject(device
, true, force
, &err
);
1120 hmp_handle_error(mon
, &err
);
1123 static void hmp_change_read_arg(void *opaque
, const char *password
,
1124 void *readline_opaque
)
1126 qmp_change_vnc_password(password
, NULL
);
1127 monitor_read_command(opaque
, 1);
1130 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
1132 const char *device
= qdict_get_str(qdict
, "device");
1133 const char *target
= qdict_get_str(qdict
, "target");
1134 const char *arg
= qdict_get_try_str(qdict
, "arg");
1137 if (strcmp(device
, "vnc") == 0 &&
1138 (strcmp(target
, "passwd") == 0 ||
1139 strcmp(target
, "password") == 0)) {
1141 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
1146 qmp_change(device
, target
, !!arg
, arg
, &err
);
1148 error_get_class(err
) == ERROR_CLASS_DEVICE_ENCRYPTED
) {
1150 monitor_read_block_device_key(mon
, device
, NULL
, NULL
);
1153 hmp_handle_error(mon
, &err
);
1156 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
1160 qmp_block_set_io_throttle(qdict_get_str(qdict
, "device"),
1161 qdict_get_int(qdict
, "bps"),
1162 qdict_get_int(qdict
, "bps_rd"),
1163 qdict_get_int(qdict
, "bps_wr"),
1164 qdict_get_int(qdict
, "iops"),
1165 qdict_get_int(qdict
, "iops_rd"),
1166 qdict_get_int(qdict
, "iops_wr"),
1167 false, /* no burst max via HMP */
1179 false, /* No default I/O size */
1181 hmp_handle_error(mon
, &err
);
1184 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
1186 Error
*error
= NULL
;
1187 const char *device
= qdict_get_str(qdict
, "device");
1188 const char *base
= qdict_get_try_str(qdict
, "base");
1189 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
1191 qmp_block_stream(device
, base
!= NULL
, base
, false, NULL
,
1192 qdict_haskey(qdict
, "speed"), speed
,
1193 true, BLOCKDEV_ON_ERROR_REPORT
, &error
);
1195 hmp_handle_error(mon
, &error
);
1198 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
1200 Error
*error
= NULL
;
1201 const char *device
= qdict_get_str(qdict
, "device");
1202 int64_t value
= qdict_get_int(qdict
, "speed");
1204 qmp_block_job_set_speed(device
, value
, &error
);
1206 hmp_handle_error(mon
, &error
);
1209 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
1211 Error
*error
= NULL
;
1212 const char *device
= qdict_get_str(qdict
, "device");
1213 bool force
= qdict_get_try_bool(qdict
, "force", 0);
1215 qmp_block_job_cancel(device
, true, force
, &error
);
1217 hmp_handle_error(mon
, &error
);
1220 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
1222 Error
*error
= NULL
;
1223 const char *device
= qdict_get_str(qdict
, "device");
1225 qmp_block_job_pause(device
, &error
);
1227 hmp_handle_error(mon
, &error
);
1230 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
1232 Error
*error
= NULL
;
1233 const char *device
= qdict_get_str(qdict
, "device");
1235 qmp_block_job_resume(device
, &error
);
1237 hmp_handle_error(mon
, &error
);
1240 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
1242 Error
*error
= NULL
;
1243 const char *device
= qdict_get_str(qdict
, "device");
1245 qmp_block_job_complete(device
, &error
);
1247 hmp_handle_error(mon
, &error
);
1250 typedef struct MigrationStatus
1254 bool is_block_migration
;
1257 static void hmp_migrate_status_cb(void *opaque
)
1259 MigrationStatus
*status
= opaque
;
1260 MigrationInfo
*info
;
1262 info
= qmp_query_migrate(NULL
);
1263 if (!info
->has_status
|| strcmp(info
->status
, "active") == 0 ||
1264 strcmp(info
->status
, "setup") == 0) {
1265 if (info
->has_disk
) {
1268 if (info
->disk
->remaining
) {
1269 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1274 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1275 monitor_flush(status
->mon
);
1278 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1000);
1280 if (status
->is_block_migration
) {
1281 monitor_printf(status
->mon
, "\n");
1283 monitor_resume(status
->mon
);
1284 timer_del(status
->timer
);
1288 qapi_free_MigrationInfo(info
);
1291 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1293 int detach
= qdict_get_try_bool(qdict
, "detach", 0);
1294 int blk
= qdict_get_try_bool(qdict
, "blk", 0);
1295 int inc
= qdict_get_try_bool(qdict
, "inc", 0);
1296 const char *uri
= qdict_get_str(qdict
, "uri");
1299 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
1301 monitor_printf(mon
, "migrate: %s\n", error_get_pretty(err
));
1307 MigrationStatus
*status
;
1309 if (monitor_suspend(mon
) < 0) {
1310 monitor_printf(mon
, "terminal does not allow synchronous "
1311 "migration, continuing detached\n");
1315 status
= g_malloc0(sizeof(*status
));
1317 status
->is_block_migration
= blk
|| inc
;
1318 status
->timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, hmp_migrate_status_cb
,
1320 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
1324 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1326 const char *id
= qdict_get_str(qdict
, "id");
1329 qmp_device_del(id
, &err
);
1330 hmp_handle_error(mon
, &err
);
1333 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1336 int paging
= qdict_get_try_bool(qdict
, "paging", 0);
1337 int zlib
= qdict_get_try_bool(qdict
, "zlib", 0);
1338 int lzo
= qdict_get_try_bool(qdict
, "lzo", 0);
1339 int snappy
= qdict_get_try_bool(qdict
, "snappy", 0);
1340 const char *file
= qdict_get_str(qdict
, "filename");
1341 bool has_begin
= qdict_haskey(qdict
, "begin");
1342 bool has_length
= qdict_haskey(qdict
, "length");
1345 enum DumpGuestMemoryFormat dump_format
= DUMP_GUEST_MEMORY_FORMAT_ELF
;
1348 if (zlib
+ lzo
+ snappy
> 1) {
1349 error_setg(&err
, "only one of '-z|-l|-s' can be set");
1350 hmp_handle_error(mon
, &err
);
1355 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB
;
1359 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO
;
1363 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY
;
1367 begin
= qdict_get_int(qdict
, "begin");
1370 length
= qdict_get_int(qdict
, "length");
1373 prot
= g_strconcat("file:", file
, NULL
);
1375 qmp_dump_guest_memory(paging
, prot
, has_begin
, begin
, has_length
, length
,
1376 true, dump_format
, &err
);
1377 hmp_handle_error(mon
, &err
);
1381 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
1386 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
1391 netdev_add(opts
, &err
);
1393 qemu_opts_del(opts
);
1397 hmp_handle_error(mon
, &err
);
1400 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
1402 const char *id
= qdict_get_str(qdict
, "id");
1405 qmp_netdev_del(id
, &err
);
1406 hmp_handle_error(mon
, &err
);
1409 void hmp_object_add(Monitor
*mon
, const QDict
*qdict
)
1412 Error
*err_end
= NULL
;
1420 opts
= qemu_opts_from_qdict(qemu_find_opts("object"), qdict
, &err
);
1425 ov
= opts_visitor_new(opts
);
1426 pdict
= qdict_clone_shallow(qdict
);
1428 visit_start_struct(opts_get_visitor(ov
), &dummy
, NULL
, NULL
, 0, &err
);
1433 qdict_del(pdict
, "qom-type");
1434 visit_type_str(opts_get_visitor(ov
), &type
, "qom-type", &err
);
1439 qdict_del(pdict
, "id");
1440 visit_type_str(opts_get_visitor(ov
), &id
, "id", &err
);
1445 object_add(type
, id
, pdict
, opts_get_visitor(ov
), &err
);
1448 visit_end_struct(opts_get_visitor(ov
), &err_end
);
1449 if (!err
&& err_end
) {
1450 qmp_object_del(id
, NULL
);
1452 error_propagate(&err
, err_end
);
1454 opts_visitor_cleanup(ov
);
1457 qemu_opts_del(opts
);
1463 hmp_handle_error(mon
, &err
);
1466 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
1468 const char *fdname
= qdict_get_str(qdict
, "fdname");
1471 qmp_getfd(fdname
, &err
);
1472 hmp_handle_error(mon
, &err
);
1475 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
1477 const char *fdname
= qdict_get_str(qdict
, "fdname");
1480 qmp_closefd(fdname
, &err
);
1481 hmp_handle_error(mon
, &err
);
1484 void hmp_send_key(Monitor
*mon
, const QDict
*qdict
)
1486 const char *keys
= qdict_get_str(qdict
, "keys");
1487 KeyValueList
*keylist
, *head
= NULL
, *tmp
= NULL
;
1488 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
1489 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
1491 char keyname_buf
[16];
1496 separator
= strchr(keys
, '-');
1497 keyname_len
= separator
? separator
- keys
: strlen(keys
);
1498 pstrcpy(keyname_buf
, sizeof(keyname_buf
), keys
);
1500 /* Be compatible with old interface, convert user inputted "<" */
1501 if (!strncmp(keyname_buf
, "<", 1) && keyname_len
== 1) {
1502 pstrcpy(keyname_buf
, sizeof(keyname_buf
), "less");
1505 keyname_buf
[keyname_len
] = 0;
1507 keylist
= g_malloc0(sizeof(*keylist
));
1508 keylist
->value
= g_malloc0(sizeof(*keylist
->value
));
1514 tmp
->next
= keylist
;
1518 if (strstart(keyname_buf
, "0x", NULL
)) {
1520 int value
= strtoul(keyname_buf
, &endp
, 0);
1521 if (*endp
!= '\0') {
1524 keylist
->value
->kind
= KEY_VALUE_KIND_NUMBER
;
1525 keylist
->value
->number
= value
;
1527 int idx
= index_from_key(keyname_buf
);
1528 if (idx
== Q_KEY_CODE_MAX
) {
1531 keylist
->value
->kind
= KEY_VALUE_KIND_QCODE
;
1532 keylist
->value
->qcode
= idx
;
1538 keys
= separator
+ 1;
1541 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
1542 hmp_handle_error(mon
, &err
);
1545 qapi_free_KeyValueList(head
);
1549 monitor_printf(mon
, "invalid parameter: %s\n", keyname_buf
);
1553 void hmp_screen_dump(Monitor
*mon
, const QDict
*qdict
)
1555 const char *filename
= qdict_get_str(qdict
, "filename");
1558 qmp_screendump(filename
, &err
);
1559 hmp_handle_error(mon
, &err
);
1562 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
1564 const char *uri
= qdict_get_str(qdict
, "uri");
1565 int writable
= qdict_get_try_bool(qdict
, "writable", 0);
1566 int all
= qdict_get_try_bool(qdict
, "all", 0);
1567 Error
*local_err
= NULL
;
1568 BlockInfoList
*block_list
, *info
;
1569 SocketAddress
*addr
;
1571 if (writable
&& !all
) {
1572 error_setg(&local_err
, "-w only valid together with -a");
1576 /* First check if the address is valid and start the server. */
1577 addr
= socket_parse(uri
, &local_err
);
1578 if (local_err
!= NULL
) {
1582 qmp_nbd_server_start(addr
, &local_err
);
1583 qapi_free_SocketAddress(addr
);
1584 if (local_err
!= NULL
) {
1592 /* Then try adding all block devices. If one fails, close all and
1595 block_list
= qmp_query_block(NULL
);
1597 for (info
= block_list
; info
; info
= info
->next
) {
1598 if (!info
->value
->has_inserted
) {
1602 qmp_nbd_server_add(info
->value
->device
, true, writable
, &local_err
);
1604 if (local_err
!= NULL
) {
1605 qmp_nbd_server_stop(NULL
);
1610 qapi_free_BlockInfoList(block_list
);
1613 hmp_handle_error(mon
, &local_err
);
1616 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
1618 const char *device
= qdict_get_str(qdict
, "device");
1619 int writable
= qdict_get_try_bool(qdict
, "writable", 0);
1620 Error
*local_err
= NULL
;
1622 qmp_nbd_server_add(device
, true, writable
, &local_err
);
1624 if (local_err
!= NULL
) {
1625 hmp_handle_error(mon
, &local_err
);
1629 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
1633 qmp_nbd_server_stop(&err
);
1634 hmp_handle_error(mon
, &err
);
1637 void hmp_cpu_add(Monitor
*mon
, const QDict
*qdict
)
1642 cpuid
= qdict_get_int(qdict
, "id");
1643 qmp_cpu_add(cpuid
, &err
);
1644 hmp_handle_error(mon
, &err
);
1647 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
1649 const char *args
= qdict_get_str(qdict
, "args");
1653 opts
= qemu_opts_parse(qemu_find_opts("chardev"), args
, 1);
1655 error_setg(&err
, "Parsing chardev args failed");
1657 qemu_chr_new_from_opts(opts
, NULL
, &err
);
1659 hmp_handle_error(mon
, &err
);
1662 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
1664 Error
*local_err
= NULL
;
1666 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
1667 hmp_handle_error(mon
, &local_err
);
1670 void hmp_qemu_io(Monitor
*mon
, const QDict
*qdict
)
1672 BlockDriverState
*bs
;
1673 const char* device
= qdict_get_str(qdict
, "device");
1674 const char* command
= qdict_get_str(qdict
, "command");
1677 bs
= bdrv_find(device
);
1679 qemuio_command(bs
, command
);
1681 error_set(&err
, QERR_DEVICE_NOT_FOUND
, device
);
1684 hmp_handle_error(mon
, &err
);
1687 void hmp_object_del(Monitor
*mon
, const QDict
*qdict
)
1689 const char *id
= qdict_get_str(qdict
, "id");
1692 qmp_object_del(id
, &err
);
1693 hmp_handle_error(mon
, &err
);
1696 void hmp_info_memdev(Monitor
*mon
, const QDict
*qdict
)
1699 MemdevList
*memdev_list
= qmp_query_memdev(&err
);
1700 MemdevList
*m
= memdev_list
;
1701 StringOutputVisitor
*ov
;
1707 ov
= string_output_visitor_new(false);
1708 visit_type_uint16List(string_output_get_visitor(ov
),
1709 &m
->value
->host_nodes
, NULL
, NULL
);
1710 monitor_printf(mon
, "memory backend: %d\n", i
);
1711 monitor_printf(mon
, " size: %" PRId64
"\n", m
->value
->size
);
1712 monitor_printf(mon
, " merge: %s\n",
1713 m
->value
->merge
? "true" : "false");
1714 monitor_printf(mon
, " dump: %s\n",
1715 m
->value
->dump
? "true" : "false");
1716 monitor_printf(mon
, " prealloc: %s\n",
1717 m
->value
->prealloc
? "true" : "false");
1718 monitor_printf(mon
, " policy: %s\n",
1719 HostMemPolicy_lookup
[m
->value
->policy
]);
1720 str
= string_output_get_string(ov
);
1721 monitor_printf(mon
, " host nodes: %s\n", str
);
1724 string_output_visitor_cleanup(ov
);
1729 monitor_printf(mon
, "\n");
1731 qapi_free_MemdevList(memdev_list
);
1734 void hmp_info_memory_devices(Monitor
*mon
, const QDict
*qdict
)
1737 MemoryDeviceInfoList
*info_list
= qmp_query_memory_devices(&err
);
1738 MemoryDeviceInfoList
*info
;
1739 MemoryDeviceInfo
*value
;
1740 PCDIMMDeviceInfo
*di
;
1742 for (info
= info_list
; info
; info
= info
->next
) {
1743 value
= info
->value
;
1746 switch (value
->kind
) {
1747 case MEMORY_DEVICE_INFO_KIND_DIMM
:
1750 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
1751 MemoryDeviceInfoKind_lookup
[value
->kind
],
1752 di
->id
? di
->id
: "");
1753 monitor_printf(mon
, " addr: 0x%" PRIx64
"\n", di
->addr
);
1754 monitor_printf(mon
, " slot: %" PRId64
"\n", di
->slot
);
1755 monitor_printf(mon
, " node: %" PRId64
"\n", di
->node
);
1756 monitor_printf(mon
, " size: %" PRIu64
"\n", di
->size
);
1757 monitor_printf(mon
, " memdev: %s\n", di
->memdev
);
1758 monitor_printf(mon
, " hotplugged: %s\n",
1759 di
->hotplugged
? "true" : "false");
1760 monitor_printf(mon
, " hotpluggable: %s\n",
1761 di
->hotpluggable
? "true" : "false");
1769 qapi_free_MemoryDeviceInfoList(info_list
);