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"
24 static void hmp_handle_error(Monitor
*mon
, Error
**errp
)
26 if (error_is_set(errp
)) {
27 monitor_printf(mon
, "%s\n", error_get_pretty(*errp
));
32 void hmp_info_name(Monitor
*mon
)
36 info
= qmp_query_name(NULL
);
38 monitor_printf(mon
, "%s\n", info
->name
);
40 qapi_free_NameInfo(info
);
43 void hmp_info_version(Monitor
*mon
)
47 info
= qmp_query_version(NULL
);
49 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
50 info
->qemu
.major
, info
->qemu
.minor
, info
->qemu
.micro
,
53 qapi_free_VersionInfo(info
);
56 void hmp_info_kvm(Monitor
*mon
)
60 info
= qmp_query_kvm(NULL
);
61 monitor_printf(mon
, "kvm support: ");
63 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
65 monitor_printf(mon
, "not compiled\n");
68 qapi_free_KvmInfo(info
);
71 void hmp_info_status(Monitor
*mon
)
75 info
= qmp_query_status(NULL
);
77 monitor_printf(mon
, "VM status: %s%s",
78 info
->running
? "running" : "paused",
79 info
->singlestep
? " (single step mode)" : "");
81 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
82 monitor_printf(mon
, " (%s)", RunState_lookup
[info
->status
]);
85 monitor_printf(mon
, "\n");
87 qapi_free_StatusInfo(info
);
90 void hmp_info_uuid(Monitor
*mon
)
94 info
= qmp_query_uuid(NULL
);
95 monitor_printf(mon
, "%s\n", info
->UUID
);
96 qapi_free_UuidInfo(info
);
99 void hmp_info_chardev(Monitor
*mon
)
101 ChardevInfoList
*char_info
, *info
;
103 char_info
= qmp_query_chardev(NULL
);
104 for (info
= char_info
; info
; info
= info
->next
) {
105 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
106 info
->value
->filename
);
109 qapi_free_ChardevInfoList(char_info
);
112 void hmp_info_mice(Monitor
*mon
)
114 MouseInfoList
*mice_list
, *mouse
;
116 mice_list
= qmp_query_mice(NULL
);
118 monitor_printf(mon
, "No mouse devices connected\n");
122 for (mouse
= mice_list
; mouse
; mouse
= mouse
->next
) {
123 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s%s\n",
124 mouse
->value
->current
? '*' : ' ',
125 mouse
->value
->index
, mouse
->value
->name
,
126 mouse
->value
->absolute
? " (absolute)" : "");
129 qapi_free_MouseInfoList(mice_list
);
132 void hmp_info_migrate(Monitor
*mon
)
135 MigrationCapabilityStatusList
*caps
, *cap
;
137 info
= qmp_query_migrate(NULL
);
138 caps
= qmp_query_migrate_capabilities(NULL
);
140 /* do not display parameters during setup */
141 if (info
->has_status
&& caps
) {
142 monitor_printf(mon
, "capabilities: ");
143 for (cap
= caps
; cap
; cap
= cap
->next
) {
144 monitor_printf(mon
, "%s: %s ",
145 MigrationCapability_lookup
[cap
->value
->capability
],
146 cap
->value
->state
? "on" : "off");
148 monitor_printf(mon
, "\n");
151 if (info
->has_status
) {
152 monitor_printf(mon
, "Migration status: %s\n", info
->status
);
153 monitor_printf(mon
, "total time: %" PRIu64
" milliseconds\n",
158 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
159 info
->ram
->transferred
>> 10);
160 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
161 info
->ram
->remaining
>> 10);
162 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
163 info
->ram
->total
>> 10);
164 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
165 info
->ram
->duplicate
);
166 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
168 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
169 info
->ram
->normal_bytes
>> 10);
172 if (info
->has_disk
) {
173 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
174 info
->disk
->transferred
>> 10);
175 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
176 info
->disk
->remaining
>> 10);
177 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
178 info
->disk
->total
>> 10);
181 if (info
->has_xbzrle_cache
) {
182 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
183 info
->xbzrle_cache
->cache_size
);
184 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
185 info
->xbzrle_cache
->bytes
>> 10);
186 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
187 info
->xbzrle_cache
->pages
);
188 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
"\n",
189 info
->xbzrle_cache
->cache_miss
);
190 monitor_printf(mon
, "xbzrle overflow : %" PRIu64
"\n",
191 info
->xbzrle_cache
->overflow
);
194 qapi_free_MigrationInfo(info
);
195 qapi_free_MigrationCapabilityStatusList(caps
);
198 void hmp_info_migrate_capabilities(Monitor
*mon
)
200 MigrationCapabilityStatusList
*caps
, *cap
;
202 caps
= qmp_query_migrate_capabilities(NULL
);
205 monitor_printf(mon
, "capabilities: ");
206 for (cap
= caps
; cap
; cap
= cap
->next
) {
207 monitor_printf(mon
, "%s: %s ",
208 MigrationCapability_lookup
[cap
->value
->capability
],
209 cap
->value
->state
? "on" : "off");
211 monitor_printf(mon
, "\n");
214 qapi_free_MigrationCapabilityStatusList(caps
);
217 void hmp_info_migrate_cache_size(Monitor
*mon
)
219 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
220 qmp_query_migrate_cache_size(NULL
) >> 10);
223 void hmp_info_cpus(Monitor
*mon
)
225 CpuInfoList
*cpu_list
, *cpu
;
227 cpu_list
= qmp_query_cpus(NULL
);
229 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
232 if (cpu
->value
->CPU
== monitor_get_cpu_index()) {
236 monitor_printf(mon
, "%c CPU #%" PRId64
": ", active
, cpu
->value
->CPU
);
238 if (cpu
->value
->has_pc
) {
239 monitor_printf(mon
, "pc=0x%016" PRIx64
, cpu
->value
->pc
);
241 if (cpu
->value
->has_nip
) {
242 monitor_printf(mon
, "nip=0x%016" PRIx64
, cpu
->value
->nip
);
244 if (cpu
->value
->has_npc
) {
245 monitor_printf(mon
, "pc=0x%016" PRIx64
, cpu
->value
->pc
);
246 monitor_printf(mon
, "npc=0x%016" PRIx64
, cpu
->value
->npc
);
248 if (cpu
->value
->has_PC
) {
249 monitor_printf(mon
, "PC=0x%016" PRIx64
, cpu
->value
->PC
);
252 if (cpu
->value
->halted
) {
253 monitor_printf(mon
, " (halted)");
256 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
259 qapi_free_CpuInfoList(cpu_list
);
262 void hmp_info_block(Monitor
*mon
)
264 BlockInfoList
*block_list
, *info
;
266 block_list
= qmp_query_block(NULL
);
268 for (info
= block_list
; info
; info
= info
->next
) {
269 monitor_printf(mon
, "%s: removable=%d",
270 info
->value
->device
, info
->value
->removable
);
272 if (info
->value
->removable
) {
273 monitor_printf(mon
, " locked=%d", info
->value
->locked
);
274 monitor_printf(mon
, " tray-open=%d", info
->value
->tray_open
);
277 if (info
->value
->has_io_status
) {
278 monitor_printf(mon
, " io-status=%s",
279 BlockDeviceIoStatus_lookup
[info
->value
->io_status
]);
282 if (info
->value
->has_inserted
) {
283 monitor_printf(mon
, " file=");
284 monitor_print_filename(mon
, info
->value
->inserted
->file
);
286 if (info
->value
->inserted
->has_backing_file
) {
287 monitor_printf(mon
, " backing_file=");
288 monitor_print_filename(mon
, info
->value
->inserted
->backing_file
);
289 monitor_printf(mon
, " backing_file_depth=%" PRId64
,
290 info
->value
->inserted
->backing_file_depth
);
292 monitor_printf(mon
, " ro=%d drv=%s encrypted=%d",
293 info
->value
->inserted
->ro
,
294 info
->value
->inserted
->drv
,
295 info
->value
->inserted
->encrypted
);
297 monitor_printf(mon
, " bps=%" PRId64
" bps_rd=%" PRId64
298 " bps_wr=%" PRId64
" iops=%" PRId64
299 " iops_rd=%" PRId64
" iops_wr=%" PRId64
,
300 info
->value
->inserted
->bps
,
301 info
->value
->inserted
->bps_rd
,
302 info
->value
->inserted
->bps_wr
,
303 info
->value
->inserted
->iops
,
304 info
->value
->inserted
->iops_rd
,
305 info
->value
->inserted
->iops_wr
);
307 monitor_printf(mon
, " [not inserted]");
310 monitor_printf(mon
, "\n");
313 qapi_free_BlockInfoList(block_list
);
316 void hmp_info_blockstats(Monitor
*mon
)
318 BlockStatsList
*stats_list
, *stats
;
320 stats_list
= qmp_query_blockstats(NULL
);
322 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
323 if (!stats
->value
->has_device
) {
327 monitor_printf(mon
, "%s:", stats
->value
->device
);
328 monitor_printf(mon
, " rd_bytes=%" PRId64
330 " rd_operations=%" PRId64
331 " wr_operations=%" PRId64
332 " flush_operations=%" PRId64
333 " wr_total_time_ns=%" PRId64
334 " rd_total_time_ns=%" PRId64
335 " flush_total_time_ns=%" PRId64
337 stats
->value
->stats
->rd_bytes
,
338 stats
->value
->stats
->wr_bytes
,
339 stats
->value
->stats
->rd_operations
,
340 stats
->value
->stats
->wr_operations
,
341 stats
->value
->stats
->flush_operations
,
342 stats
->value
->stats
->wr_total_time_ns
,
343 stats
->value
->stats
->rd_total_time_ns
,
344 stats
->value
->stats
->flush_total_time_ns
);
347 qapi_free_BlockStatsList(stats_list
);
350 void hmp_info_vnc(Monitor
*mon
)
354 VncClientInfoList
*client
;
356 info
= qmp_query_vnc(&err
);
358 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
363 if (!info
->enabled
) {
364 monitor_printf(mon
, "Server: disabled\n");
368 monitor_printf(mon
, "Server:\n");
369 if (info
->has_host
&& info
->has_service
) {
370 monitor_printf(mon
, " address: %s:%s\n", info
->host
, info
->service
);
372 if (info
->has_auth
) {
373 monitor_printf(mon
, " auth: %s\n", info
->auth
);
376 if (!info
->has_clients
|| info
->clients
== NULL
) {
377 monitor_printf(mon
, "Client: none\n");
379 for (client
= info
->clients
; client
; client
= client
->next
) {
380 monitor_printf(mon
, "Client:\n");
381 monitor_printf(mon
, " address: %s:%s\n",
382 client
->value
->host
, client
->value
->service
);
383 monitor_printf(mon
, " x509_dname: %s\n",
384 client
->value
->x509_dname
?
385 client
->value
->x509_dname
: "none");
386 monitor_printf(mon
, " username: %s\n",
387 client
->value
->has_sasl_username
?
388 client
->value
->sasl_username
: "none");
393 qapi_free_VncInfo(info
);
396 void hmp_info_spice(Monitor
*mon
)
398 SpiceChannelList
*chan
;
401 info
= qmp_query_spice(NULL
);
403 if (!info
->enabled
) {
404 monitor_printf(mon
, "Server: disabled\n");
408 monitor_printf(mon
, "Server:\n");
409 if (info
->has_port
) {
410 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
411 info
->host
, info
->port
);
413 if (info
->has_tls_port
) {
414 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
415 info
->host
, info
->tls_port
);
417 monitor_printf(mon
, " auth: %s\n", info
->auth
);
418 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
419 monitor_printf(mon
, " mouse-mode: %s\n",
420 SpiceQueryMouseMode_lookup
[info
->mouse_mode
]);
422 if (!info
->has_channels
|| info
->channels
== NULL
) {
423 monitor_printf(mon
, "Channels: none\n");
425 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
426 monitor_printf(mon
, "Channel:\n");
427 monitor_printf(mon
, " address: %s:%s%s\n",
428 chan
->value
->host
, chan
->value
->port
,
429 chan
->value
->tls
? " [tls]" : "");
430 monitor_printf(mon
, " session: %" PRId64
"\n",
431 chan
->value
->connection_id
);
432 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
433 chan
->value
->channel_type
, chan
->value
->channel_id
);
438 qapi_free_SpiceInfo(info
);
441 void hmp_info_balloon(Monitor
*mon
)
446 info
= qmp_query_balloon(&err
);
448 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
453 monitor_printf(mon
, "balloon: actual=%" PRId64
, info
->actual
>> 20);
454 if (info
->has_mem_swapped_in
) {
455 monitor_printf(mon
, " mem_swapped_in=%" PRId64
, info
->mem_swapped_in
);
457 if (info
->has_mem_swapped_out
) {
458 monitor_printf(mon
, " mem_swapped_out=%" PRId64
, info
->mem_swapped_out
);
460 if (info
->has_major_page_faults
) {
461 monitor_printf(mon
, " major_page_faults=%" PRId64
,
462 info
->major_page_faults
);
464 if (info
->has_minor_page_faults
) {
465 monitor_printf(mon
, " minor_page_faults=%" PRId64
,
466 info
->minor_page_faults
);
468 if (info
->has_free_mem
) {
469 monitor_printf(mon
, " free_mem=%" PRId64
, info
->free_mem
);
471 if (info
->has_total_mem
) {
472 monitor_printf(mon
, " total_mem=%" PRId64
, info
->total_mem
);
475 monitor_printf(mon
, "\n");
477 qapi_free_BalloonInfo(info
);
480 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
482 PciMemoryRegionList
*region
;
484 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
485 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
486 dev
->slot
, dev
->function
);
487 monitor_printf(mon
, " ");
489 if (dev
->class_info
.has_desc
) {
490 monitor_printf(mon
, "%s", dev
->class_info
.desc
);
492 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
.class);
495 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
496 dev
->id
.vendor
, dev
->id
.device
);
499 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
502 if (dev
->has_pci_bridge
) {
503 monitor_printf(mon
, " BUS %" PRId64
".\n",
504 dev
->pci_bridge
->bus
.number
);
505 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
506 dev
->pci_bridge
->bus
.secondary
);
507 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
508 dev
->pci_bridge
->bus
.subordinate
);
510 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
511 dev
->pci_bridge
->bus
.io_range
->base
,
512 dev
->pci_bridge
->bus
.io_range
->limit
);
515 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
516 dev
->pci_bridge
->bus
.memory_range
->base
,
517 dev
->pci_bridge
->bus
.memory_range
->limit
);
519 monitor_printf(mon
, " prefetchable memory range "
520 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
521 dev
->pci_bridge
->bus
.prefetchable_range
->base
,
522 dev
->pci_bridge
->bus
.prefetchable_range
->limit
);
525 for (region
= dev
->regions
; region
; region
= region
->next
) {
528 addr
= region
->value
->address
;
529 size
= region
->value
->size
;
531 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
533 if (!strcmp(region
->value
->type
, "io")) {
534 monitor_printf(mon
, "I/O at 0x%04" PRIx64
535 " [0x%04" PRIx64
"].\n",
536 addr
, addr
+ size
- 1);
538 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
539 " [0x%08" PRIx64
"].\n",
540 region
->value
->mem_type_64
? 64 : 32,
541 region
->value
->prefetch
? " prefetchable" : "",
542 addr
, addr
+ size
- 1);
546 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
548 if (dev
->has_pci_bridge
) {
549 if (dev
->pci_bridge
->has_devices
) {
550 PciDeviceInfoList
*cdev
;
551 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
552 hmp_info_pci_device(mon
, cdev
->value
);
558 void hmp_info_pci(Monitor
*mon
)
560 PciInfoList
*info_list
, *info
;
563 info_list
= qmp_query_pci(&err
);
565 monitor_printf(mon
, "PCI devices not supported\n");
570 for (info
= info_list
; info
; info
= info
->next
) {
571 PciDeviceInfoList
*dev
;
573 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
574 hmp_info_pci_device(mon
, dev
->value
);
578 qapi_free_PciInfoList(info_list
);
581 void hmp_info_block_jobs(Monitor
*mon
)
583 BlockJobInfoList
*list
;
586 list
= qmp_query_block_jobs(&err
);
590 monitor_printf(mon
, "No active jobs\n");
595 if (strcmp(list
->value
->type
, "stream") == 0) {
596 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
597 " of %" PRId64
" bytes, speed limit %" PRId64
604 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
605 " of %" PRId64
" bytes, speed limit %" PRId64
617 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
619 monitor_suspend(mon
);
623 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
628 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
630 qmp_system_reset(NULL
);
633 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
635 qmp_system_powerdown(NULL
);
638 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
642 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
643 use it are converted to the QAPI */
644 cpu_index
= qdict_get_int(qdict
, "index");
645 if (monitor_set_cpu(cpu_index
) < 0) {
646 monitor_printf(mon
, "invalid CPU index\n");
650 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
652 uint32_t size
= qdict_get_int(qdict
, "size");
653 const char *filename
= qdict_get_str(qdict
, "filename");
654 uint64_t addr
= qdict_get_int(qdict
, "val");
657 qmp_memsave(addr
, size
, filename
, true, monitor_get_cpu_index(), &errp
);
658 hmp_handle_error(mon
, &errp
);
661 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
663 uint32_t size
= qdict_get_int(qdict
, "size");
664 const char *filename
= qdict_get_str(qdict
, "filename");
665 uint64_t addr
= qdict_get_int(qdict
, "val");
668 qmp_pmemsave(addr
, size
, filename
, &errp
);
669 hmp_handle_error(mon
, &errp
);
672 static void hmp_cont_cb(void *opaque
, int err
)
679 static bool key_is_missing(const BlockInfo
*bdev
)
681 return (bdev
->inserted
&& bdev
->inserted
->encryption_key_missing
);
684 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
686 BlockInfoList
*bdev_list
, *bdev
;
689 bdev_list
= qmp_query_block(NULL
);
690 for (bdev
= bdev_list
; bdev
; bdev
= bdev
->next
) {
691 if (key_is_missing(bdev
->value
)) {
692 monitor_read_block_device_key(mon
, bdev
->value
->device
,
699 hmp_handle_error(mon
, &errp
);
702 qapi_free_BlockInfoList(bdev_list
);
705 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
707 qmp_system_wakeup(NULL
);
710 void hmp_inject_nmi(Monitor
*mon
, const QDict
*qdict
)
714 qmp_inject_nmi(&errp
);
715 hmp_handle_error(mon
, &errp
);
718 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
720 const char *name
= qdict_get_str(qdict
, "name");
721 int up
= qdict_get_bool(qdict
, "up");
724 qmp_set_link(name
, up
, &errp
);
725 hmp_handle_error(mon
, &errp
);
728 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
730 const char *device
= qdict_get_str(qdict
, "device");
731 const char *password
= qdict_get_str(qdict
, "password");
734 qmp_block_passwd(device
, password
, &errp
);
735 hmp_handle_error(mon
, &errp
);
738 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
740 int64_t value
= qdict_get_int(qdict
, "value");
743 qmp_balloon(value
, &errp
);
744 if (error_is_set(&errp
)) {
745 monitor_printf(mon
, "balloon: %s\n", error_get_pretty(errp
));
750 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
752 const char *device
= qdict_get_str(qdict
, "device");
753 int64_t size
= qdict_get_int(qdict
, "size");
756 qmp_block_resize(device
, size
, &errp
);
757 hmp_handle_error(mon
, &errp
);
760 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
762 const char *device
= qdict_get_str(qdict
, "device");
763 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
764 const char *format
= qdict_get_try_str(qdict
, "format");
765 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
766 enum NewImageMode mode
;
770 /* In the future, if 'snapshot-file' is not specified, the snapshot
771 will be taken internally. Today it's actually required. */
772 error_set(&errp
, QERR_MISSING_PARAMETER
, "snapshot-file");
773 hmp_handle_error(mon
, &errp
);
777 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
778 qmp_blockdev_snapshot_sync(device
, filename
, !!format
, format
,
780 hmp_handle_error(mon
, &errp
);
783 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
785 qmp_migrate_cancel(NULL
);
788 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
790 double value
= qdict_get_double(qdict
, "value");
791 qmp_migrate_set_downtime(value
, NULL
);
794 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
796 int64_t value
= qdict_get_int(qdict
, "value");
799 qmp_migrate_set_cache_size(value
, &err
);
801 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
807 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
809 int64_t value
= qdict_get_int(qdict
, "value");
810 qmp_migrate_set_speed(value
, NULL
);
813 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
815 const char *cap
= qdict_get_str(qdict
, "capability");
816 bool state
= qdict_get_bool(qdict
, "state");
818 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
821 for (i
= 0; i
< MIGRATION_CAPABILITY_MAX
; i
++) {
822 if (strcmp(cap
, MigrationCapability_lookup
[i
]) == 0) {
823 caps
->value
= g_malloc0(sizeof(*caps
->value
));
824 caps
->value
->capability
= i
;
825 caps
->value
->state
= state
;
827 qmp_migrate_set_capabilities(caps
, &err
);
832 if (i
== MIGRATION_CAPABILITY_MAX
) {
833 error_set(&err
, QERR_INVALID_PARAMETER
, cap
);
836 qapi_free_MigrationCapabilityStatusList(caps
);
839 monitor_printf(mon
, "migrate_set_parameter: %s\n",
840 error_get_pretty(err
));
845 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
847 const char *protocol
= qdict_get_str(qdict
, "protocol");
848 const char *password
= qdict_get_str(qdict
, "password");
849 const char *connected
= qdict_get_try_str(qdict
, "connected");
852 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
853 hmp_handle_error(mon
, &err
);
856 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
858 const char *protocol
= qdict_get_str(qdict
, "protocol");
859 const char *whenstr
= qdict_get_str(qdict
, "time");
862 qmp_expire_password(protocol
, whenstr
, &err
);
863 hmp_handle_error(mon
, &err
);
866 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
868 int force
= qdict_get_try_bool(qdict
, "force", 0);
869 const char *device
= qdict_get_str(qdict
, "device");
872 qmp_eject(device
, true, force
, &err
);
873 hmp_handle_error(mon
, &err
);
876 static void hmp_change_read_arg(Monitor
*mon
, const char *password
,
879 qmp_change_vnc_password(password
, NULL
);
880 monitor_read_command(mon
, 1);
883 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
885 const char *device
= qdict_get_str(qdict
, "device");
886 const char *target
= qdict_get_str(qdict
, "target");
887 const char *arg
= qdict_get_try_str(qdict
, "arg");
890 if (strcmp(device
, "vnc") == 0 &&
891 (strcmp(target
, "passwd") == 0 ||
892 strcmp(target
, "password") == 0)) {
894 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
899 qmp_change(device
, target
, !!arg
, arg
, &err
);
900 if (error_is_set(&err
) &&
901 error_get_class(err
) == ERROR_CLASS_DEVICE_ENCRYPTED
) {
903 monitor_read_block_device_key(mon
, device
, NULL
, NULL
);
906 hmp_handle_error(mon
, &err
);
909 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
913 qmp_block_set_io_throttle(qdict_get_str(qdict
, "device"),
914 qdict_get_int(qdict
, "bps"),
915 qdict_get_int(qdict
, "bps_rd"),
916 qdict_get_int(qdict
, "bps_wr"),
917 qdict_get_int(qdict
, "iops"),
918 qdict_get_int(qdict
, "iops_rd"),
919 qdict_get_int(qdict
, "iops_wr"), &err
);
920 hmp_handle_error(mon
, &err
);
923 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
926 const char *device
= qdict_get_str(qdict
, "device");
927 const char *base
= qdict_get_try_str(qdict
, "base");
928 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
930 qmp_block_stream(device
, base
!= NULL
, base
,
931 qdict_haskey(qdict
, "speed"), speed
, &error
);
933 hmp_handle_error(mon
, &error
);
936 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
939 const char *device
= qdict_get_str(qdict
, "device");
940 int64_t value
= qdict_get_int(qdict
, "speed");
942 qmp_block_job_set_speed(device
, value
, &error
);
944 hmp_handle_error(mon
, &error
);
947 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
950 const char *device
= qdict_get_str(qdict
, "device");
952 qmp_block_job_cancel(device
, &error
);
954 hmp_handle_error(mon
, &error
);
957 typedef struct MigrationStatus
961 bool is_block_migration
;
964 static void hmp_migrate_status_cb(void *opaque
)
966 MigrationStatus
*status
= opaque
;
969 info
= qmp_query_migrate(NULL
);
970 if (!info
->has_status
|| strcmp(info
->status
, "active") == 0) {
971 if (info
->has_disk
) {
974 if (info
->disk
->remaining
) {
975 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
980 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
981 monitor_flush(status
->mon
);
984 qemu_mod_timer(status
->timer
, qemu_get_clock_ms(rt_clock
) + 1000);
986 if (status
->is_block_migration
) {
987 monitor_printf(status
->mon
, "\n");
989 monitor_resume(status
->mon
);
990 qemu_del_timer(status
->timer
);
994 qapi_free_MigrationInfo(info
);
997 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
999 int detach
= qdict_get_try_bool(qdict
, "detach", 0);
1000 int blk
= qdict_get_try_bool(qdict
, "blk", 0);
1001 int inc
= qdict_get_try_bool(qdict
, "inc", 0);
1002 const char *uri
= qdict_get_str(qdict
, "uri");
1005 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
1007 monitor_printf(mon
, "migrate: %s\n", error_get_pretty(err
));
1013 MigrationStatus
*status
;
1015 if (monitor_suspend(mon
) < 0) {
1016 monitor_printf(mon
, "terminal does not allow synchronous "
1017 "migration, continuing detached\n");
1021 status
= g_malloc0(sizeof(*status
));
1023 status
->is_block_migration
= blk
|| inc
;
1024 status
->timer
= qemu_new_timer_ms(rt_clock
, hmp_migrate_status_cb
,
1026 qemu_mod_timer(status
->timer
, qemu_get_clock_ms(rt_clock
));
1030 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1032 const char *id
= qdict_get_str(qdict
, "id");
1035 qmp_device_del(id
, &err
);
1036 hmp_handle_error(mon
, &err
);
1039 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1042 int paging
= qdict_get_try_bool(qdict
, "paging", 0);
1043 const char *file
= qdict_get_str(qdict
, "protocol");
1044 bool has_begin
= qdict_haskey(qdict
, "begin");
1045 bool has_length
= qdict_haskey(qdict
, "length");
1050 begin
= qdict_get_int(qdict
, "begin");
1053 length
= qdict_get_int(qdict
, "length");
1056 qmp_dump_guest_memory(paging
, file
, has_begin
, begin
, has_length
, length
,
1058 hmp_handle_error(mon
, &errp
);
1061 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
1066 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
1067 if (error_is_set(&err
)) {
1071 netdev_add(opts
, &err
);
1072 if (error_is_set(&err
)) {
1073 qemu_opts_del(opts
);
1077 hmp_handle_error(mon
, &err
);
1080 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
1082 const char *id
= qdict_get_str(qdict
, "id");
1085 qmp_netdev_del(id
, &err
);
1086 hmp_handle_error(mon
, &err
);
1089 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
1091 const char *fdname
= qdict_get_str(qdict
, "fdname");
1094 qmp_getfd(fdname
, &errp
);
1095 hmp_handle_error(mon
, &errp
);
1098 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
1100 const char *fdname
= qdict_get_str(qdict
, "fdname");
1103 qmp_closefd(fdname
, &errp
);
1104 hmp_handle_error(mon
, &errp
);
1107 void hmp_send_key(Monitor
*mon
, const QDict
*qdict
)
1109 const char *keys
= qdict_get_str(qdict
, "keys");
1110 QKeyCodeList
*keylist
, *head
= NULL
, *tmp
= NULL
;
1111 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
1112 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
1114 char keyname_buf
[16];
1116 int keyname_len
, idx
;
1119 separator
= strchr(keys
, '-');
1120 keyname_len
= separator
? separator
- keys
: strlen(keys
);
1121 pstrcpy(keyname_buf
, sizeof(keyname_buf
), keys
);
1123 /* Be compatible with old interface, convert user inputted "<" */
1124 if (!strncmp(keyname_buf
, "<", 1) && keyname_len
== 1) {
1125 pstrcpy(keyname_buf
, sizeof(keyname_buf
), "less");
1128 keyname_buf
[keyname_len
] = 0;
1130 idx
= index_from_key(keyname_buf
);
1131 if (idx
== Q_KEY_CODE_MAX
) {
1132 monitor_printf(mon
, "invalid parameter: %s\n", keyname_buf
);
1136 keylist
= g_malloc0(sizeof(*keylist
));
1137 keylist
->value
= idx
;
1138 keylist
->next
= NULL
;
1144 tmp
->next
= keylist
;
1151 keys
= separator
+ 1;
1154 if (idx
!= Q_KEY_CODE_MAX
) {
1155 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
1157 hmp_handle_error(mon
, &err
);
1158 qapi_free_QKeyCodeList(head
);
1161 void hmp_screen_dump(Monitor
*mon
, const QDict
*qdict
)
1163 const char *filename
= qdict_get_str(qdict
, "filename");
1166 qmp_screendump(filename
, &err
);
1167 hmp_handle_error(mon
, &err
);