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
);
165 if (info
->has_disk
) {
166 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
167 info
->disk
->transferred
>> 10);
168 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
169 info
->disk
->remaining
>> 10);
170 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
171 info
->disk
->total
>> 10);
174 qapi_free_MigrationInfo(info
);
175 qapi_free_MigrationCapabilityStatusList(caps
);
178 void hmp_info_migrate_capabilities(Monitor
*mon
)
180 MigrationCapabilityStatusList
*caps
, *cap
;
182 caps
= qmp_query_migrate_capabilities(NULL
);
185 monitor_printf(mon
, "capabilities: ");
186 for (cap
= caps
; cap
; cap
= cap
->next
) {
187 monitor_printf(mon
, "%s: %s ",
188 MigrationCapability_lookup
[cap
->value
->capability
],
189 cap
->value
->state
? "on" : "off");
191 monitor_printf(mon
, "\n");
194 qapi_free_MigrationCapabilityStatusList(caps
);
197 void hmp_info_cpus(Monitor
*mon
)
199 CpuInfoList
*cpu_list
, *cpu
;
201 cpu_list
= qmp_query_cpus(NULL
);
203 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
206 if (cpu
->value
->CPU
== monitor_get_cpu_index()) {
210 monitor_printf(mon
, "%c CPU #%" PRId64
": ", active
, cpu
->value
->CPU
);
212 if (cpu
->value
->has_pc
) {
213 monitor_printf(mon
, "pc=0x%016" PRIx64
, cpu
->value
->pc
);
215 if (cpu
->value
->has_nip
) {
216 monitor_printf(mon
, "nip=0x%016" PRIx64
, cpu
->value
->nip
);
218 if (cpu
->value
->has_npc
) {
219 monitor_printf(mon
, "pc=0x%016" PRIx64
, cpu
->value
->pc
);
220 monitor_printf(mon
, "npc=0x%016" PRIx64
, cpu
->value
->npc
);
222 if (cpu
->value
->has_PC
) {
223 monitor_printf(mon
, "PC=0x%016" PRIx64
, cpu
->value
->PC
);
226 if (cpu
->value
->halted
) {
227 monitor_printf(mon
, " (halted)");
230 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
233 qapi_free_CpuInfoList(cpu_list
);
236 void hmp_info_block(Monitor
*mon
)
238 BlockInfoList
*block_list
, *info
;
240 block_list
= qmp_query_block(NULL
);
242 for (info
= block_list
; info
; info
= info
->next
) {
243 monitor_printf(mon
, "%s: removable=%d",
244 info
->value
->device
, info
->value
->removable
);
246 if (info
->value
->removable
) {
247 monitor_printf(mon
, " locked=%d", info
->value
->locked
);
248 monitor_printf(mon
, " tray-open=%d", info
->value
->tray_open
);
251 if (info
->value
->has_io_status
) {
252 monitor_printf(mon
, " io-status=%s",
253 BlockDeviceIoStatus_lookup
[info
->value
->io_status
]);
256 if (info
->value
->has_inserted
) {
257 monitor_printf(mon
, " file=");
258 monitor_print_filename(mon
, info
->value
->inserted
->file
);
260 if (info
->value
->inserted
->has_backing_file
) {
261 monitor_printf(mon
, " backing_file=");
262 monitor_print_filename(mon
, info
->value
->inserted
->backing_file
);
263 monitor_printf(mon
, " backing_file_depth=%" PRId64
,
264 info
->value
->inserted
->backing_file_depth
);
266 monitor_printf(mon
, " ro=%d drv=%s encrypted=%d",
267 info
->value
->inserted
->ro
,
268 info
->value
->inserted
->drv
,
269 info
->value
->inserted
->encrypted
);
271 monitor_printf(mon
, " bps=%" PRId64
" bps_rd=%" PRId64
272 " bps_wr=%" PRId64
" iops=%" PRId64
273 " iops_rd=%" PRId64
" iops_wr=%" PRId64
,
274 info
->value
->inserted
->bps
,
275 info
->value
->inserted
->bps_rd
,
276 info
->value
->inserted
->bps_wr
,
277 info
->value
->inserted
->iops
,
278 info
->value
->inserted
->iops_rd
,
279 info
->value
->inserted
->iops_wr
);
281 monitor_printf(mon
, " [not inserted]");
284 monitor_printf(mon
, "\n");
287 qapi_free_BlockInfoList(block_list
);
290 void hmp_info_blockstats(Monitor
*mon
)
292 BlockStatsList
*stats_list
, *stats
;
294 stats_list
= qmp_query_blockstats(NULL
);
296 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
297 if (!stats
->value
->has_device
) {
301 monitor_printf(mon
, "%s:", stats
->value
->device
);
302 monitor_printf(mon
, " rd_bytes=%" PRId64
304 " rd_operations=%" PRId64
305 " wr_operations=%" PRId64
306 " flush_operations=%" PRId64
307 " wr_total_time_ns=%" PRId64
308 " rd_total_time_ns=%" PRId64
309 " flush_total_time_ns=%" PRId64
311 stats
->value
->stats
->rd_bytes
,
312 stats
->value
->stats
->wr_bytes
,
313 stats
->value
->stats
->rd_operations
,
314 stats
->value
->stats
->wr_operations
,
315 stats
->value
->stats
->flush_operations
,
316 stats
->value
->stats
->wr_total_time_ns
,
317 stats
->value
->stats
->rd_total_time_ns
,
318 stats
->value
->stats
->flush_total_time_ns
);
321 qapi_free_BlockStatsList(stats_list
);
324 void hmp_info_vnc(Monitor
*mon
)
328 VncClientInfoList
*client
;
330 info
= qmp_query_vnc(&err
);
332 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
337 if (!info
->enabled
) {
338 monitor_printf(mon
, "Server: disabled\n");
342 monitor_printf(mon
, "Server:\n");
343 if (info
->has_host
&& info
->has_service
) {
344 monitor_printf(mon
, " address: %s:%s\n", info
->host
, info
->service
);
346 if (info
->has_auth
) {
347 monitor_printf(mon
, " auth: %s\n", info
->auth
);
350 if (!info
->has_clients
|| info
->clients
== NULL
) {
351 monitor_printf(mon
, "Client: none\n");
353 for (client
= info
->clients
; client
; client
= client
->next
) {
354 monitor_printf(mon
, "Client:\n");
355 monitor_printf(mon
, " address: %s:%s\n",
356 client
->value
->host
, client
->value
->service
);
357 monitor_printf(mon
, " x509_dname: %s\n",
358 client
->value
->x509_dname
?
359 client
->value
->x509_dname
: "none");
360 monitor_printf(mon
, " username: %s\n",
361 client
->value
->has_sasl_username
?
362 client
->value
->sasl_username
: "none");
367 qapi_free_VncInfo(info
);
370 void hmp_info_spice(Monitor
*mon
)
372 SpiceChannelList
*chan
;
375 info
= qmp_query_spice(NULL
);
377 if (!info
->enabled
) {
378 monitor_printf(mon
, "Server: disabled\n");
382 monitor_printf(mon
, "Server:\n");
383 if (info
->has_port
) {
384 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
385 info
->host
, info
->port
);
387 if (info
->has_tls_port
) {
388 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
389 info
->host
, info
->tls_port
);
391 monitor_printf(mon
, " auth: %s\n", info
->auth
);
392 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
393 monitor_printf(mon
, " mouse-mode: %s\n",
394 SpiceQueryMouseMode_lookup
[info
->mouse_mode
]);
396 if (!info
->has_channels
|| info
->channels
== NULL
) {
397 monitor_printf(mon
, "Channels: none\n");
399 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
400 monitor_printf(mon
, "Channel:\n");
401 monitor_printf(mon
, " address: %s:%s%s\n",
402 chan
->value
->host
, chan
->value
->port
,
403 chan
->value
->tls
? " [tls]" : "");
404 monitor_printf(mon
, " session: %" PRId64
"\n",
405 chan
->value
->connection_id
);
406 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
407 chan
->value
->channel_type
, chan
->value
->channel_id
);
412 qapi_free_SpiceInfo(info
);
415 void hmp_info_balloon(Monitor
*mon
)
420 info
= qmp_query_balloon(&err
);
422 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
427 monitor_printf(mon
, "balloon: actual=%" PRId64
, info
->actual
>> 20);
428 if (info
->has_mem_swapped_in
) {
429 monitor_printf(mon
, " mem_swapped_in=%" PRId64
, info
->mem_swapped_in
);
431 if (info
->has_mem_swapped_out
) {
432 monitor_printf(mon
, " mem_swapped_out=%" PRId64
, info
->mem_swapped_out
);
434 if (info
->has_major_page_faults
) {
435 monitor_printf(mon
, " major_page_faults=%" PRId64
,
436 info
->major_page_faults
);
438 if (info
->has_minor_page_faults
) {
439 monitor_printf(mon
, " minor_page_faults=%" PRId64
,
440 info
->minor_page_faults
);
442 if (info
->has_free_mem
) {
443 monitor_printf(mon
, " free_mem=%" PRId64
, info
->free_mem
);
445 if (info
->has_total_mem
) {
446 monitor_printf(mon
, " total_mem=%" PRId64
, info
->total_mem
);
449 monitor_printf(mon
, "\n");
451 qapi_free_BalloonInfo(info
);
454 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
456 PciMemoryRegionList
*region
;
458 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
459 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
460 dev
->slot
, dev
->function
);
461 monitor_printf(mon
, " ");
463 if (dev
->class_info
.has_desc
) {
464 monitor_printf(mon
, "%s", dev
->class_info
.desc
);
466 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
.class);
469 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
470 dev
->id
.vendor
, dev
->id
.device
);
473 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
476 if (dev
->has_pci_bridge
) {
477 monitor_printf(mon
, " BUS %" PRId64
".\n",
478 dev
->pci_bridge
->bus
.number
);
479 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
480 dev
->pci_bridge
->bus
.secondary
);
481 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
482 dev
->pci_bridge
->bus
.subordinate
);
484 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
485 dev
->pci_bridge
->bus
.io_range
->base
,
486 dev
->pci_bridge
->bus
.io_range
->limit
);
489 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
490 dev
->pci_bridge
->bus
.memory_range
->base
,
491 dev
->pci_bridge
->bus
.memory_range
->limit
);
493 monitor_printf(mon
, " prefetchable memory range "
494 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
495 dev
->pci_bridge
->bus
.prefetchable_range
->base
,
496 dev
->pci_bridge
->bus
.prefetchable_range
->limit
);
499 for (region
= dev
->regions
; region
; region
= region
->next
) {
502 addr
= region
->value
->address
;
503 size
= region
->value
->size
;
505 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
507 if (!strcmp(region
->value
->type
, "io")) {
508 monitor_printf(mon
, "I/O at 0x%04" PRIx64
509 " [0x%04" PRIx64
"].\n",
510 addr
, addr
+ size
- 1);
512 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
513 " [0x%08" PRIx64
"].\n",
514 region
->value
->mem_type_64
? 64 : 32,
515 region
->value
->prefetch
? " prefetchable" : "",
516 addr
, addr
+ size
- 1);
520 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
522 if (dev
->has_pci_bridge
) {
523 if (dev
->pci_bridge
->has_devices
) {
524 PciDeviceInfoList
*cdev
;
525 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
526 hmp_info_pci_device(mon
, cdev
->value
);
532 void hmp_info_pci(Monitor
*mon
)
534 PciInfoList
*info_list
, *info
;
537 info_list
= qmp_query_pci(&err
);
539 monitor_printf(mon
, "PCI devices not supported\n");
544 for (info
= info_list
; info
; info
= info
->next
) {
545 PciDeviceInfoList
*dev
;
547 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
548 hmp_info_pci_device(mon
, dev
->value
);
552 qapi_free_PciInfoList(info_list
);
555 void hmp_info_block_jobs(Monitor
*mon
)
557 BlockJobInfoList
*list
;
560 list
= qmp_query_block_jobs(&err
);
564 monitor_printf(mon
, "No active jobs\n");
569 if (strcmp(list
->value
->type
, "stream") == 0) {
570 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
571 " of %" PRId64
" bytes, speed limit %" PRId64
578 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
579 " of %" PRId64
" bytes, speed limit %" PRId64
591 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
593 monitor_suspend(mon
);
597 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
602 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
604 qmp_system_reset(NULL
);
607 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
609 qmp_system_powerdown(NULL
);
612 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
616 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
617 use it are converted to the QAPI */
618 cpu_index
= qdict_get_int(qdict
, "index");
619 if (monitor_set_cpu(cpu_index
) < 0) {
620 monitor_printf(mon
, "invalid CPU index\n");
624 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
626 uint32_t size
= qdict_get_int(qdict
, "size");
627 const char *filename
= qdict_get_str(qdict
, "filename");
628 uint64_t addr
= qdict_get_int(qdict
, "val");
631 qmp_memsave(addr
, size
, filename
, true, monitor_get_cpu_index(), &errp
);
632 hmp_handle_error(mon
, &errp
);
635 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
637 uint32_t size
= qdict_get_int(qdict
, "size");
638 const char *filename
= qdict_get_str(qdict
, "filename");
639 uint64_t addr
= qdict_get_int(qdict
, "val");
642 qmp_pmemsave(addr
, size
, filename
, &errp
);
643 hmp_handle_error(mon
, &errp
);
646 static void hmp_cont_cb(void *opaque
, int err
)
648 Monitor
*mon
= opaque
;
655 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
660 if (error_is_set(&errp
)) {
661 if (error_is_type(errp
, QERR_DEVICE_ENCRYPTED
)) {
664 /* The device is encrypted. Ask the user for the password
667 device
= error_get_field(errp
, "device");
668 assert(device
!= NULL
);
670 monitor_read_block_device_key(mon
, device
, hmp_cont_cb
, mon
);
674 hmp_handle_error(mon
, &errp
);
678 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
680 qmp_system_wakeup(NULL
);
683 void hmp_inject_nmi(Monitor
*mon
, const QDict
*qdict
)
687 qmp_inject_nmi(&errp
);
688 hmp_handle_error(mon
, &errp
);
691 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
693 const char *name
= qdict_get_str(qdict
, "name");
694 int up
= qdict_get_bool(qdict
, "up");
697 qmp_set_link(name
, up
, &errp
);
698 hmp_handle_error(mon
, &errp
);
701 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
703 const char *device
= qdict_get_str(qdict
, "device");
704 const char *password
= qdict_get_str(qdict
, "password");
707 qmp_block_passwd(device
, password
, &errp
);
708 hmp_handle_error(mon
, &errp
);
711 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
713 int64_t value
= qdict_get_int(qdict
, "value");
716 qmp_balloon(value
, &errp
);
717 if (error_is_set(&errp
)) {
718 monitor_printf(mon
, "balloon: %s\n", error_get_pretty(errp
));
723 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
725 const char *device
= qdict_get_str(qdict
, "device");
726 int64_t size
= qdict_get_int(qdict
, "size");
729 qmp_block_resize(device
, size
, &errp
);
730 hmp_handle_error(mon
, &errp
);
733 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
735 const char *device
= qdict_get_str(qdict
, "device");
736 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
737 const char *format
= qdict_get_try_str(qdict
, "format");
738 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
739 enum NewImageMode mode
;
743 /* In the future, if 'snapshot-file' is not specified, the snapshot
744 will be taken internally. Today it's actually required. */
745 error_set(&errp
, QERR_MISSING_PARAMETER
, "snapshot-file");
746 hmp_handle_error(mon
, &errp
);
750 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
751 qmp_blockdev_snapshot_sync(device
, filename
, !!format
, format
,
753 hmp_handle_error(mon
, &errp
);
756 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
758 qmp_migrate_cancel(NULL
);
761 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
763 double value
= qdict_get_double(qdict
, "value");
764 qmp_migrate_set_downtime(value
, NULL
);
767 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
769 int64_t value
= qdict_get_int(qdict
, "value");
770 qmp_migrate_set_speed(value
, NULL
);
773 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
775 const char *cap
= qdict_get_str(qdict
, "capability");
776 bool state
= qdict_get_bool(qdict
, "state");
778 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
781 for (i
= 0; i
< MIGRATION_CAPABILITY_MAX
; i
++) {
782 if (strcmp(cap
, MigrationCapability_lookup
[i
]) == 0) {
783 caps
->value
= g_malloc0(sizeof(*caps
->value
));
784 caps
->value
->capability
= i
;
785 caps
->value
->state
= state
;
787 qmp_migrate_set_capabilities(caps
, &err
);
792 if (i
== MIGRATION_CAPABILITY_MAX
) {
793 error_set(&err
, QERR_INVALID_PARAMETER
, cap
);
796 qapi_free_MigrationCapabilityStatusList(caps
);
799 monitor_printf(mon
, "migrate_set_parameter: %s\n",
800 error_get_pretty(err
));
805 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
807 const char *protocol
= qdict_get_str(qdict
, "protocol");
808 const char *password
= qdict_get_str(qdict
, "password");
809 const char *connected
= qdict_get_try_str(qdict
, "connected");
812 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
813 hmp_handle_error(mon
, &err
);
816 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
818 const char *protocol
= qdict_get_str(qdict
, "protocol");
819 const char *whenstr
= qdict_get_str(qdict
, "time");
822 qmp_expire_password(protocol
, whenstr
, &err
);
823 hmp_handle_error(mon
, &err
);
826 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
828 int force
= qdict_get_try_bool(qdict
, "force", 0);
829 const char *device
= qdict_get_str(qdict
, "device");
832 qmp_eject(device
, true, force
, &err
);
833 hmp_handle_error(mon
, &err
);
836 static void hmp_change_read_arg(Monitor
*mon
, const char *password
,
839 qmp_change_vnc_password(password
, NULL
);
840 monitor_read_command(mon
, 1);
843 static void cb_hmp_change_bdrv_pwd(Monitor
*mon
, const char *password
,
846 Error
*encryption_err
= opaque
;
850 device
= error_get_field(encryption_err
, "device");
852 qmp_block_passwd(device
, password
, &err
);
853 hmp_handle_error(mon
, &err
);
854 error_free(encryption_err
);
856 monitor_read_command(mon
, 1);
859 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
861 const char *device
= qdict_get_str(qdict
, "device");
862 const char *target
= qdict_get_str(qdict
, "target");
863 const char *arg
= qdict_get_try_str(qdict
, "arg");
866 if (strcmp(device
, "vnc") == 0 &&
867 (strcmp(target
, "passwd") == 0 ||
868 strcmp(target
, "password") == 0)) {
870 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
875 qmp_change(device
, target
, !!arg
, arg
, &err
);
876 if (error_is_type(err
, QERR_DEVICE_ENCRYPTED
)) {
877 monitor_printf(mon
, "%s (%s) is encrypted.\n",
878 error_get_field(err
, "device"),
879 error_get_field(err
, "filename"));
880 if (!monitor_get_rs(mon
)) {
882 "terminal does not support password prompting\n");
886 readline_start(monitor_get_rs(mon
), "Password: ", 1,
887 cb_hmp_change_bdrv_pwd
, err
);
890 hmp_handle_error(mon
, &err
);
893 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
897 qmp_block_set_io_throttle(qdict_get_str(qdict
, "device"),
898 qdict_get_int(qdict
, "bps"),
899 qdict_get_int(qdict
, "bps_rd"),
900 qdict_get_int(qdict
, "bps_wr"),
901 qdict_get_int(qdict
, "iops"),
902 qdict_get_int(qdict
, "iops_rd"),
903 qdict_get_int(qdict
, "iops_wr"), &err
);
904 hmp_handle_error(mon
, &err
);
907 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
910 const char *device
= qdict_get_str(qdict
, "device");
911 const char *base
= qdict_get_try_str(qdict
, "base");
912 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
914 qmp_block_stream(device
, base
!= NULL
, base
,
915 qdict_haskey(qdict
, "speed"), speed
, &error
);
917 hmp_handle_error(mon
, &error
);
920 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
923 const char *device
= qdict_get_str(qdict
, "device");
924 int64_t value
= qdict_get_int(qdict
, "speed");
926 qmp_block_job_set_speed(device
, value
, &error
);
928 hmp_handle_error(mon
, &error
);
931 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
934 const char *device
= qdict_get_str(qdict
, "device");
936 qmp_block_job_cancel(device
, &error
);
938 hmp_handle_error(mon
, &error
);
941 typedef struct MigrationStatus
945 bool is_block_migration
;
948 static void hmp_migrate_status_cb(void *opaque
)
950 MigrationStatus
*status
= opaque
;
953 info
= qmp_query_migrate(NULL
);
954 if (!info
->has_status
|| strcmp(info
->status
, "active") == 0) {
955 if (info
->has_disk
) {
958 if (info
->disk
->remaining
) {
959 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
964 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
965 monitor_flush(status
->mon
);
968 qemu_mod_timer(status
->timer
, qemu_get_clock_ms(rt_clock
) + 1000);
970 if (status
->is_block_migration
) {
971 monitor_printf(status
->mon
, "\n");
973 monitor_resume(status
->mon
);
974 qemu_del_timer(status
->timer
);
978 qapi_free_MigrationInfo(info
);
981 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
983 int detach
= qdict_get_try_bool(qdict
, "detach", 0);
984 int blk
= qdict_get_try_bool(qdict
, "blk", 0);
985 int inc
= qdict_get_try_bool(qdict
, "inc", 0);
986 const char *uri
= qdict_get_str(qdict
, "uri");
989 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
991 monitor_printf(mon
, "migrate: %s\n", error_get_pretty(err
));
997 MigrationStatus
*status
;
999 if (monitor_suspend(mon
) < 0) {
1000 monitor_printf(mon
, "terminal does not allow synchronous "
1001 "migration, continuing detached\n");
1005 status
= g_malloc0(sizeof(*status
));
1007 status
->is_block_migration
= blk
|| inc
;
1008 status
->timer
= qemu_new_timer_ms(rt_clock
, hmp_migrate_status_cb
,
1010 qemu_mod_timer(status
->timer
, qemu_get_clock_ms(rt_clock
));
1014 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1016 const char *id
= qdict_get_str(qdict
, "id");
1019 qmp_device_del(id
, &err
);
1020 hmp_handle_error(mon
, &err
);
1023 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1026 int paging
= qdict_get_try_bool(qdict
, "paging", 0);
1027 const char *file
= qdict_get_str(qdict
, "protocol");
1028 bool has_begin
= qdict_haskey(qdict
, "begin");
1029 bool has_length
= qdict_haskey(qdict
, "length");
1034 begin
= qdict_get_int(qdict
, "begin");
1037 length
= qdict_get_int(qdict
, "length");
1040 qmp_dump_guest_memory(paging
, file
, has_begin
, begin
, has_length
, length
,
1042 hmp_handle_error(mon
, &errp
);
1045 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
1050 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
1051 if (error_is_set(&err
)) {
1055 netdev_add(opts
, &err
);
1056 if (error_is_set(&err
)) {
1057 qemu_opts_del(opts
);
1061 hmp_handle_error(mon
, &err
);
1064 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
1066 const char *id
= qdict_get_str(qdict
, "id");
1069 qmp_netdev_del(id
, &err
);
1070 hmp_handle_error(mon
, &err
);
1073 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
1075 const char *fdname
= qdict_get_str(qdict
, "fdname");
1078 qmp_getfd(fdname
, &errp
);
1079 hmp_handle_error(mon
, &errp
);
1082 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
1084 const char *fdname
= qdict_get_str(qdict
, "fdname");
1087 qmp_closefd(fdname
, &errp
);
1088 hmp_handle_error(mon
, &errp
);