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 "qemu-option.h"
19 #include "qemu-timer.h"
20 #include "qmp-commands.h"
23 static void hmp_handle_error(Monitor
*mon
, Error
**errp
)
25 if (error_is_set(errp
)) {
26 monitor_printf(mon
, "%s\n", error_get_pretty(*errp
));
31 void hmp_info_name(Monitor
*mon
)
35 info
= qmp_query_name(NULL
);
37 monitor_printf(mon
, "%s\n", info
->name
);
39 qapi_free_NameInfo(info
);
42 void hmp_info_version(Monitor
*mon
)
46 info
= qmp_query_version(NULL
);
48 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
49 info
->qemu
.major
, info
->qemu
.minor
, info
->qemu
.micro
,
52 qapi_free_VersionInfo(info
);
55 void hmp_info_kvm(Monitor
*mon
)
59 info
= qmp_query_kvm(NULL
);
60 monitor_printf(mon
, "kvm support: ");
62 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
64 monitor_printf(mon
, "not compiled\n");
67 qapi_free_KvmInfo(info
);
70 void hmp_info_status(Monitor
*mon
)
74 info
= qmp_query_status(NULL
);
76 monitor_printf(mon
, "VM status: %s%s",
77 info
->running
? "running" : "paused",
78 info
->singlestep
? " (single step mode)" : "");
80 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
81 monitor_printf(mon
, " (%s)", RunState_lookup
[info
->status
]);
84 monitor_printf(mon
, "\n");
86 qapi_free_StatusInfo(info
);
89 void hmp_info_uuid(Monitor
*mon
)
93 info
= qmp_query_uuid(NULL
);
94 monitor_printf(mon
, "%s\n", info
->UUID
);
95 qapi_free_UuidInfo(info
);
98 void hmp_info_chardev(Monitor
*mon
)
100 ChardevInfoList
*char_info
, *info
;
102 char_info
= qmp_query_chardev(NULL
);
103 for (info
= char_info
; info
; info
= info
->next
) {
104 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
105 info
->value
->filename
);
108 qapi_free_ChardevInfoList(char_info
);
111 void hmp_info_mice(Monitor
*mon
)
113 MouseInfoList
*mice_list
, *mouse
;
115 mice_list
= qmp_query_mice(NULL
);
117 monitor_printf(mon
, "No mouse devices connected\n");
121 for (mouse
= mice_list
; mouse
; mouse
= mouse
->next
) {
122 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s%s\n",
123 mouse
->value
->current
? '*' : ' ',
124 mouse
->value
->index
, mouse
->value
->name
,
125 mouse
->value
->absolute
? " (absolute)" : "");
128 qapi_free_MouseInfoList(mice_list
);
131 void hmp_info_migrate(Monitor
*mon
)
134 MigrationCapabilityStatusList
*caps
, *cap
;
136 info
= qmp_query_migrate(NULL
);
137 caps
= qmp_query_migrate_capabilities(NULL
);
139 /* do not display parameters during setup */
140 if (info
->has_status
&& caps
) {
141 monitor_printf(mon
, "capabilities: ");
142 for (cap
= caps
; cap
; cap
= cap
->next
) {
143 monitor_printf(mon
, "%s: %s ",
144 MigrationCapability_lookup
[cap
->value
->capability
],
145 cap
->value
->state
? "on" : "off");
147 monitor_printf(mon
, "\n");
150 if (info
->has_status
) {
151 monitor_printf(mon
, "Migration status: %s\n", info
->status
);
155 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
156 info
->ram
->transferred
>> 10);
157 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
158 info
->ram
->remaining
>> 10);
159 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
160 info
->ram
->total
>> 10);
161 monitor_printf(mon
, "total time: %" PRIu64
" milliseconds\n",
162 info
->ram
->total_time
);
163 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
164 info
->ram
->duplicate
);
165 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
167 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
168 info
->ram
->normal_bytes
>> 10);
171 if (info
->has_disk
) {
172 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
173 info
->disk
->transferred
>> 10);
174 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
175 info
->disk
->remaining
>> 10);
176 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
177 info
->disk
->total
>> 10);
180 qapi_free_MigrationInfo(info
);
181 qapi_free_MigrationCapabilityStatusList(caps
);
184 void hmp_info_migrate_capabilities(Monitor
*mon
)
186 MigrationCapabilityStatusList
*caps
, *cap
;
188 caps
= qmp_query_migrate_capabilities(NULL
);
191 monitor_printf(mon
, "capabilities: ");
192 for (cap
= caps
; cap
; cap
= cap
->next
) {
193 monitor_printf(mon
, "%s: %s ",
194 MigrationCapability_lookup
[cap
->value
->capability
],
195 cap
->value
->state
? "on" : "off");
197 monitor_printf(mon
, "\n");
200 qapi_free_MigrationCapabilityStatusList(caps
);
203 void hmp_info_migrate_cache_size(Monitor
*mon
)
205 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
206 qmp_query_migrate_cache_size(NULL
) >> 10);
209 void hmp_info_cpus(Monitor
*mon
)
211 CpuInfoList
*cpu_list
, *cpu
;
213 cpu_list
= qmp_query_cpus(NULL
);
215 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
218 if (cpu
->value
->CPU
== monitor_get_cpu_index()) {
222 monitor_printf(mon
, "%c CPU #%" PRId64
": ", active
, cpu
->value
->CPU
);
224 if (cpu
->value
->has_pc
) {
225 monitor_printf(mon
, "pc=0x%016" PRIx64
, cpu
->value
->pc
);
227 if (cpu
->value
->has_nip
) {
228 monitor_printf(mon
, "nip=0x%016" PRIx64
, cpu
->value
->nip
);
230 if (cpu
->value
->has_npc
) {
231 monitor_printf(mon
, "pc=0x%016" PRIx64
, cpu
->value
->pc
);
232 monitor_printf(mon
, "npc=0x%016" PRIx64
, cpu
->value
->npc
);
234 if (cpu
->value
->has_PC
) {
235 monitor_printf(mon
, "PC=0x%016" PRIx64
, cpu
->value
->PC
);
238 if (cpu
->value
->halted
) {
239 monitor_printf(mon
, " (halted)");
242 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
245 qapi_free_CpuInfoList(cpu_list
);
248 void hmp_info_block(Monitor
*mon
)
250 BlockInfoList
*block_list
, *info
;
252 block_list
= qmp_query_block(NULL
);
254 for (info
= block_list
; info
; info
= info
->next
) {
255 monitor_printf(mon
, "%s: removable=%d",
256 info
->value
->device
, info
->value
->removable
);
258 if (info
->value
->removable
) {
259 monitor_printf(mon
, " locked=%d", info
->value
->locked
);
260 monitor_printf(mon
, " tray-open=%d", info
->value
->tray_open
);
263 if (info
->value
->has_io_status
) {
264 monitor_printf(mon
, " io-status=%s",
265 BlockDeviceIoStatus_lookup
[info
->value
->io_status
]);
268 if (info
->value
->has_inserted
) {
269 monitor_printf(mon
, " file=");
270 monitor_print_filename(mon
, info
->value
->inserted
->file
);
272 if (info
->value
->inserted
->has_backing_file
) {
273 monitor_printf(mon
, " backing_file=");
274 monitor_print_filename(mon
, info
->value
->inserted
->backing_file
);
275 monitor_printf(mon
, " backing_file_depth=%" PRId64
,
276 info
->value
->inserted
->backing_file_depth
);
278 monitor_printf(mon
, " ro=%d drv=%s encrypted=%d",
279 info
->value
->inserted
->ro
,
280 info
->value
->inserted
->drv
,
281 info
->value
->inserted
->encrypted
);
283 monitor_printf(mon
, " bps=%" PRId64
" bps_rd=%" PRId64
284 " bps_wr=%" PRId64
" iops=%" PRId64
285 " iops_rd=%" PRId64
" iops_wr=%" PRId64
,
286 info
->value
->inserted
->bps
,
287 info
->value
->inserted
->bps_rd
,
288 info
->value
->inserted
->bps_wr
,
289 info
->value
->inserted
->iops
,
290 info
->value
->inserted
->iops_rd
,
291 info
->value
->inserted
->iops_wr
);
293 monitor_printf(mon
, " [not inserted]");
296 monitor_printf(mon
, "\n");
299 qapi_free_BlockInfoList(block_list
);
302 void hmp_info_blockstats(Monitor
*mon
)
304 BlockStatsList
*stats_list
, *stats
;
306 stats_list
= qmp_query_blockstats(NULL
);
308 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
309 if (!stats
->value
->has_device
) {
313 monitor_printf(mon
, "%s:", stats
->value
->device
);
314 monitor_printf(mon
, " rd_bytes=%" PRId64
316 " rd_operations=%" PRId64
317 " wr_operations=%" PRId64
318 " flush_operations=%" PRId64
319 " wr_total_time_ns=%" PRId64
320 " rd_total_time_ns=%" PRId64
321 " flush_total_time_ns=%" PRId64
323 stats
->value
->stats
->rd_bytes
,
324 stats
->value
->stats
->wr_bytes
,
325 stats
->value
->stats
->rd_operations
,
326 stats
->value
->stats
->wr_operations
,
327 stats
->value
->stats
->flush_operations
,
328 stats
->value
->stats
->wr_total_time_ns
,
329 stats
->value
->stats
->rd_total_time_ns
,
330 stats
->value
->stats
->flush_total_time_ns
);
333 qapi_free_BlockStatsList(stats_list
);
336 void hmp_info_vnc(Monitor
*mon
)
340 VncClientInfoList
*client
;
342 info
= qmp_query_vnc(&err
);
344 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
349 if (!info
->enabled
) {
350 monitor_printf(mon
, "Server: disabled\n");
354 monitor_printf(mon
, "Server:\n");
355 if (info
->has_host
&& info
->has_service
) {
356 monitor_printf(mon
, " address: %s:%s\n", info
->host
, info
->service
);
358 if (info
->has_auth
) {
359 monitor_printf(mon
, " auth: %s\n", info
->auth
);
362 if (!info
->has_clients
|| info
->clients
== NULL
) {
363 monitor_printf(mon
, "Client: none\n");
365 for (client
= info
->clients
; client
; client
= client
->next
) {
366 monitor_printf(mon
, "Client:\n");
367 monitor_printf(mon
, " address: %s:%s\n",
368 client
->value
->host
, client
->value
->service
);
369 monitor_printf(mon
, " x509_dname: %s\n",
370 client
->value
->x509_dname
?
371 client
->value
->x509_dname
: "none");
372 monitor_printf(mon
, " username: %s\n",
373 client
->value
->has_sasl_username
?
374 client
->value
->sasl_username
: "none");
379 qapi_free_VncInfo(info
);
382 void hmp_info_spice(Monitor
*mon
)
384 SpiceChannelList
*chan
;
387 info
= qmp_query_spice(NULL
);
389 if (!info
->enabled
) {
390 monitor_printf(mon
, "Server: disabled\n");
394 monitor_printf(mon
, "Server:\n");
395 if (info
->has_port
) {
396 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
397 info
->host
, info
->port
);
399 if (info
->has_tls_port
) {
400 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
401 info
->host
, info
->tls_port
);
403 monitor_printf(mon
, " auth: %s\n", info
->auth
);
404 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
405 monitor_printf(mon
, " mouse-mode: %s\n",
406 SpiceQueryMouseMode_lookup
[info
->mouse_mode
]);
408 if (!info
->has_channels
|| info
->channels
== NULL
) {
409 monitor_printf(mon
, "Channels: none\n");
411 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
412 monitor_printf(mon
, "Channel:\n");
413 monitor_printf(mon
, " address: %s:%s%s\n",
414 chan
->value
->host
, chan
->value
->port
,
415 chan
->value
->tls
? " [tls]" : "");
416 monitor_printf(mon
, " session: %" PRId64
"\n",
417 chan
->value
->connection_id
);
418 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
419 chan
->value
->channel_type
, chan
->value
->channel_id
);
424 qapi_free_SpiceInfo(info
);
427 void hmp_info_balloon(Monitor
*mon
)
432 info
= qmp_query_balloon(&err
);
434 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
439 monitor_printf(mon
, "balloon: actual=%" PRId64
, info
->actual
>> 20);
440 if (info
->has_mem_swapped_in
) {
441 monitor_printf(mon
, " mem_swapped_in=%" PRId64
, info
->mem_swapped_in
);
443 if (info
->has_mem_swapped_out
) {
444 monitor_printf(mon
, " mem_swapped_out=%" PRId64
, info
->mem_swapped_out
);
446 if (info
->has_major_page_faults
) {
447 monitor_printf(mon
, " major_page_faults=%" PRId64
,
448 info
->major_page_faults
);
450 if (info
->has_minor_page_faults
) {
451 monitor_printf(mon
, " minor_page_faults=%" PRId64
,
452 info
->minor_page_faults
);
454 if (info
->has_free_mem
) {
455 monitor_printf(mon
, " free_mem=%" PRId64
, info
->free_mem
);
457 if (info
->has_total_mem
) {
458 monitor_printf(mon
, " total_mem=%" PRId64
, info
->total_mem
);
461 monitor_printf(mon
, "\n");
463 qapi_free_BalloonInfo(info
);
466 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
468 PciMemoryRegionList
*region
;
470 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
471 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
472 dev
->slot
, dev
->function
);
473 monitor_printf(mon
, " ");
475 if (dev
->class_info
.has_desc
) {
476 monitor_printf(mon
, "%s", dev
->class_info
.desc
);
478 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
.class);
481 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
482 dev
->id
.vendor
, dev
->id
.device
);
485 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
488 if (dev
->has_pci_bridge
) {
489 monitor_printf(mon
, " BUS %" PRId64
".\n",
490 dev
->pci_bridge
->bus
.number
);
491 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
492 dev
->pci_bridge
->bus
.secondary
);
493 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
494 dev
->pci_bridge
->bus
.subordinate
);
496 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
497 dev
->pci_bridge
->bus
.io_range
->base
,
498 dev
->pci_bridge
->bus
.io_range
->limit
);
501 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
502 dev
->pci_bridge
->bus
.memory_range
->base
,
503 dev
->pci_bridge
->bus
.memory_range
->limit
);
505 monitor_printf(mon
, " prefetchable memory range "
506 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
507 dev
->pci_bridge
->bus
.prefetchable_range
->base
,
508 dev
->pci_bridge
->bus
.prefetchable_range
->limit
);
511 for (region
= dev
->regions
; region
; region
= region
->next
) {
514 addr
= region
->value
->address
;
515 size
= region
->value
->size
;
517 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
519 if (!strcmp(region
->value
->type
, "io")) {
520 monitor_printf(mon
, "I/O at 0x%04" PRIx64
521 " [0x%04" PRIx64
"].\n",
522 addr
, addr
+ size
- 1);
524 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
525 " [0x%08" PRIx64
"].\n",
526 region
->value
->mem_type_64
? 64 : 32,
527 region
->value
->prefetch
? " prefetchable" : "",
528 addr
, addr
+ size
- 1);
532 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
534 if (dev
->has_pci_bridge
) {
535 if (dev
->pci_bridge
->has_devices
) {
536 PciDeviceInfoList
*cdev
;
537 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
538 hmp_info_pci_device(mon
, cdev
->value
);
544 void hmp_info_pci(Monitor
*mon
)
546 PciInfoList
*info_list
, *info
;
549 info_list
= qmp_query_pci(&err
);
551 monitor_printf(mon
, "PCI devices not supported\n");
556 for (info
= info_list
; info
; info
= info
->next
) {
557 PciDeviceInfoList
*dev
;
559 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
560 hmp_info_pci_device(mon
, dev
->value
);
564 qapi_free_PciInfoList(info_list
);
567 void hmp_info_block_jobs(Monitor
*mon
)
569 BlockJobInfoList
*list
;
572 list
= qmp_query_block_jobs(&err
);
576 monitor_printf(mon
, "No active jobs\n");
581 if (strcmp(list
->value
->type
, "stream") == 0) {
582 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
583 " of %" PRId64
" bytes, speed limit %" PRId64
590 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
591 " of %" PRId64
" bytes, speed limit %" PRId64
603 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
605 monitor_suspend(mon
);
609 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
614 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
616 qmp_system_reset(NULL
);
619 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
621 qmp_system_powerdown(NULL
);
624 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
628 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
629 use it are converted to the QAPI */
630 cpu_index
= qdict_get_int(qdict
, "index");
631 if (monitor_set_cpu(cpu_index
) < 0) {
632 monitor_printf(mon
, "invalid CPU index\n");
636 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
638 uint32_t size
= qdict_get_int(qdict
, "size");
639 const char *filename
= qdict_get_str(qdict
, "filename");
640 uint64_t addr
= qdict_get_int(qdict
, "val");
643 qmp_memsave(addr
, size
, filename
, true, monitor_get_cpu_index(), &errp
);
644 hmp_handle_error(mon
, &errp
);
647 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
649 uint32_t size
= qdict_get_int(qdict
, "size");
650 const char *filename
= qdict_get_str(qdict
, "filename");
651 uint64_t addr
= qdict_get_int(qdict
, "val");
654 qmp_pmemsave(addr
, size
, filename
, &errp
);
655 hmp_handle_error(mon
, &errp
);
658 static void hmp_cont_cb(void *opaque
, int err
)
660 Monitor
*mon
= opaque
;
667 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
672 if (error_is_set(&errp
)) {
673 if (error_is_type(errp
, QERR_DEVICE_ENCRYPTED
)) {
676 /* The device is encrypted. Ask the user for the password
679 device
= error_get_field(errp
, "device");
680 assert(device
!= NULL
);
682 monitor_read_block_device_key(mon
, device
, hmp_cont_cb
, mon
);
686 hmp_handle_error(mon
, &errp
);
690 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
692 qmp_system_wakeup(NULL
);
695 void hmp_inject_nmi(Monitor
*mon
, const QDict
*qdict
)
699 qmp_inject_nmi(&errp
);
700 hmp_handle_error(mon
, &errp
);
703 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
705 const char *name
= qdict_get_str(qdict
, "name");
706 int up
= qdict_get_bool(qdict
, "up");
709 qmp_set_link(name
, up
, &errp
);
710 hmp_handle_error(mon
, &errp
);
713 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
715 const char *device
= qdict_get_str(qdict
, "device");
716 const char *password
= qdict_get_str(qdict
, "password");
719 qmp_block_passwd(device
, password
, &errp
);
720 hmp_handle_error(mon
, &errp
);
723 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
725 int64_t value
= qdict_get_int(qdict
, "value");
728 qmp_balloon(value
, &errp
);
729 if (error_is_set(&errp
)) {
730 monitor_printf(mon
, "balloon: %s\n", error_get_pretty(errp
));
735 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
737 const char *device
= qdict_get_str(qdict
, "device");
738 int64_t size
= qdict_get_int(qdict
, "size");
741 qmp_block_resize(device
, size
, &errp
);
742 hmp_handle_error(mon
, &errp
);
745 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
747 const char *device
= qdict_get_str(qdict
, "device");
748 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
749 const char *format
= qdict_get_try_str(qdict
, "format");
750 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
751 enum NewImageMode mode
;
755 /* In the future, if 'snapshot-file' is not specified, the snapshot
756 will be taken internally. Today it's actually required. */
757 error_set(&errp
, QERR_MISSING_PARAMETER
, "snapshot-file");
758 hmp_handle_error(mon
, &errp
);
762 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
763 qmp_blockdev_snapshot_sync(device
, filename
, !!format
, format
,
765 hmp_handle_error(mon
, &errp
);
768 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
770 qmp_migrate_cancel(NULL
);
773 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
775 double value
= qdict_get_double(qdict
, "value");
776 qmp_migrate_set_downtime(value
, NULL
);
779 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
781 int64_t value
= qdict_get_int(qdict
, "value");
784 qmp_migrate_set_cache_size(value
, &err
);
786 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
792 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
794 int64_t value
= qdict_get_int(qdict
, "value");
795 qmp_migrate_set_speed(value
, NULL
);
798 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
800 const char *cap
= qdict_get_str(qdict
, "capability");
801 bool state
= qdict_get_bool(qdict
, "state");
803 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
806 for (i
= 0; i
< MIGRATION_CAPABILITY_MAX
; i
++) {
807 if (strcmp(cap
, MigrationCapability_lookup
[i
]) == 0) {
808 caps
->value
= g_malloc0(sizeof(*caps
->value
));
809 caps
->value
->capability
= i
;
810 caps
->value
->state
= state
;
812 qmp_migrate_set_capabilities(caps
, &err
);
817 if (i
== MIGRATION_CAPABILITY_MAX
) {
818 error_set(&err
, QERR_INVALID_PARAMETER
, cap
);
821 qapi_free_MigrationCapabilityStatusList(caps
);
824 monitor_printf(mon
, "migrate_set_parameter: %s\n",
825 error_get_pretty(err
));
830 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
832 const char *protocol
= qdict_get_str(qdict
, "protocol");
833 const char *password
= qdict_get_str(qdict
, "password");
834 const char *connected
= qdict_get_try_str(qdict
, "connected");
837 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
838 hmp_handle_error(mon
, &err
);
841 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
843 const char *protocol
= qdict_get_str(qdict
, "protocol");
844 const char *whenstr
= qdict_get_str(qdict
, "time");
847 qmp_expire_password(protocol
, whenstr
, &err
);
848 hmp_handle_error(mon
, &err
);
851 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
853 int force
= qdict_get_try_bool(qdict
, "force", 0);
854 const char *device
= qdict_get_str(qdict
, "device");
857 qmp_eject(device
, true, force
, &err
);
858 hmp_handle_error(mon
, &err
);
861 static void hmp_change_read_arg(Monitor
*mon
, const char *password
,
864 qmp_change_vnc_password(password
, NULL
);
865 monitor_read_command(mon
, 1);
868 static void cb_hmp_change_bdrv_pwd(Monitor
*mon
, const char *password
,
871 Error
*encryption_err
= opaque
;
875 device
= error_get_field(encryption_err
, "device");
877 qmp_block_passwd(device
, password
, &err
);
878 hmp_handle_error(mon
, &err
);
879 error_free(encryption_err
);
881 monitor_read_command(mon
, 1);
884 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
886 const char *device
= qdict_get_str(qdict
, "device");
887 const char *target
= qdict_get_str(qdict
, "target");
888 const char *arg
= qdict_get_try_str(qdict
, "arg");
891 if (strcmp(device
, "vnc") == 0 &&
892 (strcmp(target
, "passwd") == 0 ||
893 strcmp(target
, "password") == 0)) {
895 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
900 qmp_change(device
, target
, !!arg
, arg
, &err
);
901 if (error_is_type(err
, QERR_DEVICE_ENCRYPTED
)) {
902 monitor_printf(mon
, "%s (%s) is encrypted.\n",
903 error_get_field(err
, "device"),
904 error_get_field(err
, "filename"));
905 if (!monitor_get_rs(mon
)) {
907 "terminal does not support password prompting\n");
911 readline_start(monitor_get_rs(mon
), "Password: ", 1,
912 cb_hmp_change_bdrv_pwd
, err
);
915 hmp_handle_error(mon
, &err
);
918 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
922 qmp_block_set_io_throttle(qdict_get_str(qdict
, "device"),
923 qdict_get_int(qdict
, "bps"),
924 qdict_get_int(qdict
, "bps_rd"),
925 qdict_get_int(qdict
, "bps_wr"),
926 qdict_get_int(qdict
, "iops"),
927 qdict_get_int(qdict
, "iops_rd"),
928 qdict_get_int(qdict
, "iops_wr"), &err
);
929 hmp_handle_error(mon
, &err
);
932 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
935 const char *device
= qdict_get_str(qdict
, "device");
936 const char *base
= qdict_get_try_str(qdict
, "base");
937 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
939 qmp_block_stream(device
, base
!= NULL
, base
,
940 qdict_haskey(qdict
, "speed"), speed
, &error
);
942 hmp_handle_error(mon
, &error
);
945 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
948 const char *device
= qdict_get_str(qdict
, "device");
949 int64_t value
= qdict_get_int(qdict
, "speed");
951 qmp_block_job_set_speed(device
, value
, &error
);
953 hmp_handle_error(mon
, &error
);
956 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
959 const char *device
= qdict_get_str(qdict
, "device");
961 qmp_block_job_cancel(device
, &error
);
963 hmp_handle_error(mon
, &error
);
966 typedef struct MigrationStatus
970 bool is_block_migration
;
973 static void hmp_migrate_status_cb(void *opaque
)
975 MigrationStatus
*status
= opaque
;
978 info
= qmp_query_migrate(NULL
);
979 if (!info
->has_status
|| strcmp(info
->status
, "active") == 0) {
980 if (info
->has_disk
) {
983 if (info
->disk
->remaining
) {
984 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
989 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
990 monitor_flush(status
->mon
);
993 qemu_mod_timer(status
->timer
, qemu_get_clock_ms(rt_clock
) + 1000);
995 if (status
->is_block_migration
) {
996 monitor_printf(status
->mon
, "\n");
998 monitor_resume(status
->mon
);
999 qemu_del_timer(status
->timer
);
1003 qapi_free_MigrationInfo(info
);
1006 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1008 int detach
= qdict_get_try_bool(qdict
, "detach", 0);
1009 int blk
= qdict_get_try_bool(qdict
, "blk", 0);
1010 int inc
= qdict_get_try_bool(qdict
, "inc", 0);
1011 const char *uri
= qdict_get_str(qdict
, "uri");
1014 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
1016 monitor_printf(mon
, "migrate: %s\n", error_get_pretty(err
));
1022 MigrationStatus
*status
;
1024 if (monitor_suspend(mon
) < 0) {
1025 monitor_printf(mon
, "terminal does not allow synchronous "
1026 "migration, continuing detached\n");
1030 status
= g_malloc0(sizeof(*status
));
1032 status
->is_block_migration
= blk
|| inc
;
1033 status
->timer
= qemu_new_timer_ms(rt_clock
, hmp_migrate_status_cb
,
1035 qemu_mod_timer(status
->timer
, qemu_get_clock_ms(rt_clock
));
1039 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1041 const char *id
= qdict_get_str(qdict
, "id");
1044 qmp_device_del(id
, &err
);
1045 hmp_handle_error(mon
, &err
);
1048 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1051 int paging
= qdict_get_try_bool(qdict
, "paging", 0);
1052 const char *file
= qdict_get_str(qdict
, "protocol");
1053 bool has_begin
= qdict_haskey(qdict
, "begin");
1054 bool has_length
= qdict_haskey(qdict
, "length");
1059 begin
= qdict_get_int(qdict
, "begin");
1062 length
= qdict_get_int(qdict
, "length");
1065 qmp_dump_guest_memory(paging
, file
, has_begin
, begin
, has_length
, length
,
1067 hmp_handle_error(mon
, &errp
);
1070 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
1075 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
1076 if (error_is_set(&err
)) {
1080 netdev_add(opts
, &err
);
1081 if (error_is_set(&err
)) {
1082 qemu_opts_del(opts
);
1086 hmp_handle_error(mon
, &err
);
1089 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
1091 const char *id
= qdict_get_str(qdict
, "id");
1094 qmp_netdev_del(id
, &err
);
1095 hmp_handle_error(mon
, &err
);
1098 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
1100 const char *fdname
= qdict_get_str(qdict
, "fdname");
1103 qmp_getfd(fdname
, &errp
);
1104 hmp_handle_error(mon
, &errp
);
1107 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
1109 const char *fdname
= qdict_get_str(qdict
, "fdname");
1112 qmp_closefd(fdname
, &errp
);
1113 hmp_handle_error(mon
, &errp
);