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 "ui/console.h"
26 #include "block/qapi.h"
29 static void hmp_handle_error(Monitor
*mon
, Error
**errp
)
31 if (error_is_set(errp
)) {
32 monitor_printf(mon
, "%s\n", error_get_pretty(*errp
));
37 void hmp_info_name(Monitor
*mon
, const QDict
*qdict
)
41 info
= qmp_query_name(NULL
);
43 monitor_printf(mon
, "%s\n", info
->name
);
45 qapi_free_NameInfo(info
);
48 void hmp_info_version(Monitor
*mon
, const QDict
*qdict
)
52 info
= qmp_query_version(NULL
);
54 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
55 info
->qemu
.major
, info
->qemu
.minor
, info
->qemu
.micro
,
58 qapi_free_VersionInfo(info
);
61 void hmp_info_kvm(Monitor
*mon
, const QDict
*qdict
)
65 info
= qmp_query_kvm(NULL
);
66 monitor_printf(mon
, "kvm support: ");
68 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
70 monitor_printf(mon
, "not compiled\n");
73 qapi_free_KvmInfo(info
);
76 void hmp_info_status(Monitor
*mon
, const QDict
*qdict
)
80 info
= qmp_query_status(NULL
);
82 monitor_printf(mon
, "VM status: %s%s",
83 info
->running
? "running" : "paused",
84 info
->singlestep
? " (single step mode)" : "");
86 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
87 monitor_printf(mon
, " (%s)", RunState_lookup
[info
->status
]);
90 monitor_printf(mon
, "\n");
92 qapi_free_StatusInfo(info
);
95 void hmp_info_uuid(Monitor
*mon
, const QDict
*qdict
)
99 info
= qmp_query_uuid(NULL
);
100 monitor_printf(mon
, "%s\n", info
->UUID
);
101 qapi_free_UuidInfo(info
);
104 void hmp_info_chardev(Monitor
*mon
, const QDict
*qdict
)
106 ChardevInfoList
*char_info
, *info
;
108 char_info
= qmp_query_chardev(NULL
);
109 for (info
= char_info
; info
; info
= info
->next
) {
110 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
111 info
->value
->filename
);
114 qapi_free_ChardevInfoList(char_info
);
117 void hmp_info_mice(Monitor
*mon
, const QDict
*qdict
)
119 MouseInfoList
*mice_list
, *mouse
;
121 mice_list
= qmp_query_mice(NULL
);
123 monitor_printf(mon
, "No mouse devices connected\n");
127 for (mouse
= mice_list
; mouse
; mouse
= mouse
->next
) {
128 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s%s\n",
129 mouse
->value
->current
? '*' : ' ',
130 mouse
->value
->index
, mouse
->value
->name
,
131 mouse
->value
->absolute
? " (absolute)" : "");
134 qapi_free_MouseInfoList(mice_list
);
137 void hmp_info_migrate(Monitor
*mon
, const QDict
*qdict
)
140 MigrationCapabilityStatusList
*caps
, *cap
;
142 info
= qmp_query_migrate(NULL
);
143 caps
= qmp_query_migrate_capabilities(NULL
);
145 /* do not display parameters during setup */
146 if (info
->has_status
&& caps
) {
147 monitor_printf(mon
, "capabilities: ");
148 for (cap
= caps
; cap
; cap
= cap
->next
) {
149 monitor_printf(mon
, "%s: %s ",
150 MigrationCapability_lookup
[cap
->value
->capability
],
151 cap
->value
->state
? "on" : "off");
153 monitor_printf(mon
, "\n");
156 if (info
->has_status
) {
157 monitor_printf(mon
, "Migration status: %s\n", info
->status
);
158 monitor_printf(mon
, "total time: %" PRIu64
" milliseconds\n",
160 if (info
->has_expected_downtime
) {
161 monitor_printf(mon
, "expected downtime: %" PRIu64
" milliseconds\n",
162 info
->expected_downtime
);
164 if (info
->has_downtime
) {
165 monitor_printf(mon
, "downtime: %" PRIu64
" milliseconds\n",
168 if (info
->has_setup_time
) {
169 monitor_printf(mon
, "setup: %" PRIu64
" milliseconds\n",
175 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
176 info
->ram
->transferred
>> 10);
177 monitor_printf(mon
, "throughput: %0.2f mbps\n",
179 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
180 info
->ram
->remaining
>> 10);
181 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
182 info
->ram
->total
>> 10);
183 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
184 info
->ram
->duplicate
);
185 monitor_printf(mon
, "skipped: %" PRIu64
" pages\n",
187 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
189 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
190 info
->ram
->normal_bytes
>> 10);
191 monitor_printf(mon
, "dirty sync count: %" PRIu64
"\n",
192 info
->ram
->dirty_sync_count
);
193 if (info
->ram
->dirty_pages_rate
) {
194 monitor_printf(mon
, "dirty pages rate: %" PRIu64
" pages\n",
195 info
->ram
->dirty_pages_rate
);
199 if (info
->has_disk
) {
200 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
201 info
->disk
->transferred
>> 10);
202 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
203 info
->disk
->remaining
>> 10);
204 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
205 info
->disk
->total
>> 10);
208 if (info
->has_xbzrle_cache
) {
209 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
210 info
->xbzrle_cache
->cache_size
);
211 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
212 info
->xbzrle_cache
->bytes
>> 10);
213 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
214 info
->xbzrle_cache
->pages
);
215 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
"\n",
216 info
->xbzrle_cache
->cache_miss
);
217 monitor_printf(mon
, "xbzrle cache miss rate: %0.2f\n",
218 info
->xbzrle_cache
->cache_miss_rate
);
219 monitor_printf(mon
, "xbzrle overflow : %" PRIu64
"\n",
220 info
->xbzrle_cache
->overflow
);
223 qapi_free_MigrationInfo(info
);
224 qapi_free_MigrationCapabilityStatusList(caps
);
227 void hmp_info_migrate_capabilities(Monitor
*mon
, const QDict
*qdict
)
229 MigrationCapabilityStatusList
*caps
, *cap
;
231 caps
= qmp_query_migrate_capabilities(NULL
);
234 monitor_printf(mon
, "capabilities: ");
235 for (cap
= caps
; cap
; cap
= cap
->next
) {
236 monitor_printf(mon
, "%s: %s ",
237 MigrationCapability_lookup
[cap
->value
->capability
],
238 cap
->value
->state
? "on" : "off");
240 monitor_printf(mon
, "\n");
243 qapi_free_MigrationCapabilityStatusList(caps
);
246 void hmp_info_migrate_cache_size(Monitor
*mon
, const QDict
*qdict
)
248 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
249 qmp_query_migrate_cache_size(NULL
) >> 10);
252 void hmp_info_cpus(Monitor
*mon
, const QDict
*qdict
)
254 CpuInfoList
*cpu_list
, *cpu
;
256 cpu_list
= qmp_query_cpus(NULL
);
258 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
261 if (cpu
->value
->CPU
== monitor_get_cpu_index()) {
265 monitor_printf(mon
, "%c CPU #%" PRId64
":", active
, cpu
->value
->CPU
);
267 if (cpu
->value
->has_pc
) {
268 monitor_printf(mon
, " pc=0x%016" PRIx64
, cpu
->value
->pc
);
270 if (cpu
->value
->has_nip
) {
271 monitor_printf(mon
, " nip=0x%016" PRIx64
, cpu
->value
->nip
);
273 if (cpu
->value
->has_npc
) {
274 monitor_printf(mon
, " npc=0x%016" PRIx64
, cpu
->value
->npc
);
276 if (cpu
->value
->has_PC
) {
277 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->PC
);
280 if (cpu
->value
->halted
) {
281 monitor_printf(mon
, " (halted)");
284 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
287 qapi_free_CpuInfoList(cpu_list
);
290 void hmp_info_block(Monitor
*mon
, const QDict
*qdict
)
292 BlockInfoList
*block_list
, *info
;
293 ImageInfo
*image_info
;
294 const char *device
= qdict_get_try_str(qdict
, "device");
295 bool verbose
= qdict_get_try_bool(qdict
, "verbose", 0);
297 block_list
= qmp_query_block(NULL
);
299 for (info
= block_list
; info
; info
= info
->next
) {
300 if (device
&& strcmp(device
, info
->value
->device
)) {
304 if (info
!= block_list
) {
305 monitor_printf(mon
, "\n");
308 monitor_printf(mon
, "%s", info
->value
->device
);
309 if (info
->value
->has_inserted
) {
310 monitor_printf(mon
, ": %s (%s%s%s)\n",
311 info
->value
->inserted
->file
,
312 info
->value
->inserted
->drv
,
313 info
->value
->inserted
->ro
? ", read-only" : "",
314 info
->value
->inserted
->encrypted
? ", encrypted" : "");
316 monitor_printf(mon
, ": [not inserted]\n");
319 if (info
->value
->has_io_status
&& info
->value
->io_status
!= BLOCK_DEVICE_IO_STATUS_OK
) {
320 monitor_printf(mon
, " I/O status: %s\n",
321 BlockDeviceIoStatus_lookup
[info
->value
->io_status
]);
324 if (info
->value
->removable
) {
325 monitor_printf(mon
, " Removable device: %slocked, tray %s\n",
326 info
->value
->locked
? "" : "not ",
327 info
->value
->tray_open
? "open" : "closed");
331 if (!info
->value
->has_inserted
) {
335 if (info
->value
->inserted
->has_backing_file
) {
338 "(chain depth: %" PRId64
")\n",
339 info
->value
->inserted
->backing_file
,
340 info
->value
->inserted
->backing_file_depth
);
343 if (info
->value
->inserted
->bps
344 || info
->value
->inserted
->bps_rd
345 || info
->value
->inserted
->bps_wr
346 || info
->value
->inserted
->iops
347 || info
->value
->inserted
->iops_rd
348 || info
->value
->inserted
->iops_wr
)
350 monitor_printf(mon
, " I/O throttling: bps=%" PRId64
351 " bps_rd=%" PRId64
" bps_wr=%" PRId64
353 " bps_rd_max=%" PRId64
354 " bps_wr_max=%" PRId64
355 " iops=%" PRId64
" iops_rd=%" PRId64
358 " iops_rd_max=%" PRId64
359 " iops_wr_max=%" PRId64
360 " iops_size=%" PRId64
"\n",
361 info
->value
->inserted
->bps
,
362 info
->value
->inserted
->bps_rd
,
363 info
->value
->inserted
->bps_wr
,
364 info
->value
->inserted
->bps_max
,
365 info
->value
->inserted
->bps_rd_max
,
366 info
->value
->inserted
->bps_wr_max
,
367 info
->value
->inserted
->iops
,
368 info
->value
->inserted
->iops_rd
,
369 info
->value
->inserted
->iops_wr
,
370 info
->value
->inserted
->iops_max
,
371 info
->value
->inserted
->iops_rd_max
,
372 info
->value
->inserted
->iops_wr_max
,
373 info
->value
->inserted
->iops_size
);
377 monitor_printf(mon
, "\nImages:\n");
378 image_info
= info
->value
->inserted
->image
;
380 bdrv_image_info_dump((fprintf_function
)monitor_printf
,
382 if (image_info
->has_backing_image
) {
383 image_info
= image_info
->backing_image
;
391 qapi_free_BlockInfoList(block_list
);
394 void hmp_info_blockstats(Monitor
*mon
, const QDict
*qdict
)
396 BlockStatsList
*stats_list
, *stats
;
398 stats_list
= qmp_query_blockstats(NULL
);
400 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
401 if (!stats
->value
->has_device
) {
405 monitor_printf(mon
, "%s:", stats
->value
->device
);
406 monitor_printf(mon
, " rd_bytes=%" PRId64
408 " rd_operations=%" PRId64
409 " wr_operations=%" PRId64
410 " flush_operations=%" PRId64
411 " wr_total_time_ns=%" PRId64
412 " rd_total_time_ns=%" PRId64
413 " flush_total_time_ns=%" PRId64
415 stats
->value
->stats
->rd_bytes
,
416 stats
->value
->stats
->wr_bytes
,
417 stats
->value
->stats
->rd_operations
,
418 stats
->value
->stats
->wr_operations
,
419 stats
->value
->stats
->flush_operations
,
420 stats
->value
->stats
->wr_total_time_ns
,
421 stats
->value
->stats
->rd_total_time_ns
,
422 stats
->value
->stats
->flush_total_time_ns
);
425 qapi_free_BlockStatsList(stats_list
);
428 void hmp_info_vnc(Monitor
*mon
, const QDict
*qdict
)
432 VncClientInfoList
*client
;
434 info
= qmp_query_vnc(&err
);
436 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
441 if (!info
->enabled
) {
442 monitor_printf(mon
, "Server: disabled\n");
446 monitor_printf(mon
, "Server:\n");
447 if (info
->has_host
&& info
->has_service
) {
448 monitor_printf(mon
, " address: %s:%s\n", info
->host
, info
->service
);
450 if (info
->has_auth
) {
451 monitor_printf(mon
, " auth: %s\n", info
->auth
);
454 if (!info
->has_clients
|| info
->clients
== NULL
) {
455 monitor_printf(mon
, "Client: none\n");
457 for (client
= info
->clients
; client
; client
= client
->next
) {
458 monitor_printf(mon
, "Client:\n");
459 monitor_printf(mon
, " address: %s:%s\n",
460 client
->value
->host
, client
->value
->service
);
461 monitor_printf(mon
, " x509_dname: %s\n",
462 client
->value
->x509_dname
?
463 client
->value
->x509_dname
: "none");
464 monitor_printf(mon
, " username: %s\n",
465 client
->value
->has_sasl_username
?
466 client
->value
->sasl_username
: "none");
471 qapi_free_VncInfo(info
);
474 void hmp_info_spice(Monitor
*mon
, const QDict
*qdict
)
476 SpiceChannelList
*chan
;
479 info
= qmp_query_spice(NULL
);
481 if (!info
->enabled
) {
482 monitor_printf(mon
, "Server: disabled\n");
486 monitor_printf(mon
, "Server:\n");
487 if (info
->has_port
) {
488 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
489 info
->host
, info
->port
);
491 if (info
->has_tls_port
) {
492 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
493 info
->host
, info
->tls_port
);
495 monitor_printf(mon
, " migrated: %s\n",
496 info
->migrated
? "true" : "false");
497 monitor_printf(mon
, " auth: %s\n", info
->auth
);
498 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
499 monitor_printf(mon
, " mouse-mode: %s\n",
500 SpiceQueryMouseMode_lookup
[info
->mouse_mode
]);
502 if (!info
->has_channels
|| info
->channels
== NULL
) {
503 monitor_printf(mon
, "Channels: none\n");
505 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
506 monitor_printf(mon
, "Channel:\n");
507 monitor_printf(mon
, " address: %s:%s%s\n",
508 chan
->value
->host
, chan
->value
->port
,
509 chan
->value
->tls
? " [tls]" : "");
510 monitor_printf(mon
, " session: %" PRId64
"\n",
511 chan
->value
->connection_id
);
512 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
513 chan
->value
->channel_type
, chan
->value
->channel_id
);
518 qapi_free_SpiceInfo(info
);
521 void hmp_info_balloon(Monitor
*mon
, const QDict
*qdict
)
526 info
= qmp_query_balloon(&err
);
528 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
533 monitor_printf(mon
, "balloon: actual=%" PRId64
"\n", info
->actual
>> 20);
535 qapi_free_BalloonInfo(info
);
538 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
540 PciMemoryRegionList
*region
;
542 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
543 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
544 dev
->slot
, dev
->function
);
545 monitor_printf(mon
, " ");
547 if (dev
->class_info
.has_desc
) {
548 monitor_printf(mon
, "%s", dev
->class_info
.desc
);
550 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
.q_class
);
553 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
554 dev
->id
.vendor
, dev
->id
.device
);
557 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
560 if (dev
->has_pci_bridge
) {
561 monitor_printf(mon
, " BUS %" PRId64
".\n",
562 dev
->pci_bridge
->bus
.number
);
563 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
564 dev
->pci_bridge
->bus
.secondary
);
565 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
566 dev
->pci_bridge
->bus
.subordinate
);
568 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
569 dev
->pci_bridge
->bus
.io_range
->base
,
570 dev
->pci_bridge
->bus
.io_range
->limit
);
573 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
574 dev
->pci_bridge
->bus
.memory_range
->base
,
575 dev
->pci_bridge
->bus
.memory_range
->limit
);
577 monitor_printf(mon
, " prefetchable memory range "
578 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
579 dev
->pci_bridge
->bus
.prefetchable_range
->base
,
580 dev
->pci_bridge
->bus
.prefetchable_range
->limit
);
583 for (region
= dev
->regions
; region
; region
= region
->next
) {
586 addr
= region
->value
->address
;
587 size
= region
->value
->size
;
589 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
591 if (!strcmp(region
->value
->type
, "io")) {
592 monitor_printf(mon
, "I/O at 0x%04" PRIx64
593 " [0x%04" PRIx64
"].\n",
594 addr
, addr
+ size
- 1);
596 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
597 " [0x%08" PRIx64
"].\n",
598 region
->value
->mem_type_64
? 64 : 32,
599 region
->value
->prefetch
? " prefetchable" : "",
600 addr
, addr
+ size
- 1);
604 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
606 if (dev
->has_pci_bridge
) {
607 if (dev
->pci_bridge
->has_devices
) {
608 PciDeviceInfoList
*cdev
;
609 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
610 hmp_info_pci_device(mon
, cdev
->value
);
616 void hmp_info_pci(Monitor
*mon
, const QDict
*qdict
)
618 PciInfoList
*info_list
, *info
;
621 info_list
= qmp_query_pci(&err
);
623 monitor_printf(mon
, "PCI devices not supported\n");
628 for (info
= info_list
; info
; info
= info
->next
) {
629 PciDeviceInfoList
*dev
;
631 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
632 hmp_info_pci_device(mon
, dev
->value
);
636 qapi_free_PciInfoList(info_list
);
639 void hmp_info_block_jobs(Monitor
*mon
, const QDict
*qdict
)
641 BlockJobInfoList
*list
;
644 list
= qmp_query_block_jobs(&err
);
648 monitor_printf(mon
, "No active jobs\n");
653 if (strcmp(list
->value
->type
, "stream") == 0) {
654 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
655 " of %" PRId64
" bytes, speed limit %" PRId64
662 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
663 " of %" PRId64
" bytes, speed limit %" PRId64
675 void hmp_info_tpm(Monitor
*mon
, const QDict
*qdict
)
677 TPMInfoList
*info_list
, *info
;
680 TPMPassthroughOptions
*tpo
;
682 info_list
= qmp_query_tpm(&err
);
684 monitor_printf(mon
, "TPM device not supported\n");
690 monitor_printf(mon
, "TPM device:\n");
693 for (info
= info_list
; info
; info
= info
->next
) {
694 TPMInfo
*ti
= info
->value
;
695 monitor_printf(mon
, " tpm%d: model=%s\n",
696 c
, TpmModel_lookup
[ti
->model
]);
698 monitor_printf(mon
, " \\ %s: type=%s",
699 ti
->id
, TpmTypeOptionsKind_lookup
[ti
->options
->kind
]);
701 switch (ti
->options
->kind
) {
702 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH
:
703 tpo
= ti
->options
->passthrough
;
704 monitor_printf(mon
, "%s%s%s%s",
705 tpo
->has_path
? ",path=" : "",
706 tpo
->has_path
? tpo
->path
: "",
707 tpo
->has_cancel_path
? ",cancel-path=" : "",
708 tpo
->has_cancel_path
? tpo
->cancel_path
: "");
710 case TPM_TYPE_OPTIONS_KIND_MAX
:
713 monitor_printf(mon
, "\n");
716 qapi_free_TPMInfoList(info_list
);
719 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
721 monitor_suspend(mon
);
725 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
730 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
732 qmp_system_reset(NULL
);
735 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
737 qmp_system_powerdown(NULL
);
740 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
744 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
745 use it are converted to the QAPI */
746 cpu_index
= qdict_get_int(qdict
, "index");
747 if (monitor_set_cpu(cpu_index
) < 0) {
748 monitor_printf(mon
, "invalid CPU index\n");
752 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
754 uint32_t size
= qdict_get_int(qdict
, "size");
755 const char *filename
= qdict_get_str(qdict
, "filename");
756 uint64_t addr
= qdict_get_int(qdict
, "val");
759 qmp_memsave(addr
, size
, filename
, true, monitor_get_cpu_index(), &errp
);
760 hmp_handle_error(mon
, &errp
);
763 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
765 uint32_t size
= qdict_get_int(qdict
, "size");
766 const char *filename
= qdict_get_str(qdict
, "filename");
767 uint64_t addr
= qdict_get_int(qdict
, "val");
770 qmp_pmemsave(addr
, size
, filename
, &errp
);
771 hmp_handle_error(mon
, &errp
);
774 void hmp_ringbuf_write(Monitor
*mon
, const QDict
*qdict
)
776 const char *chardev
= qdict_get_str(qdict
, "device");
777 const char *data
= qdict_get_str(qdict
, "data");
780 qmp_ringbuf_write(chardev
, data
, false, 0, &errp
);
782 hmp_handle_error(mon
, &errp
);
785 void hmp_ringbuf_read(Monitor
*mon
, const QDict
*qdict
)
787 uint32_t size
= qdict_get_int(qdict
, "size");
788 const char *chardev
= qdict_get_str(qdict
, "device");
793 data
= qmp_ringbuf_read(chardev
, size
, false, 0, &errp
);
795 monitor_printf(mon
, "%s\n", error_get_pretty(errp
));
800 for (i
= 0; data
[i
]; i
++) {
801 unsigned char ch
= data
[i
];
804 monitor_printf(mon
, "\\\\");
805 } else if ((ch
< 0x20 && ch
!= '\n' && ch
!= '\t') || ch
== 0x7F) {
806 monitor_printf(mon
, "\\u%04X", ch
);
808 monitor_printf(mon
, "%c", ch
);
812 monitor_printf(mon
, "\n");
816 static void hmp_cont_cb(void *opaque
, int err
)
823 static bool key_is_missing(const BlockInfo
*bdev
)
825 return (bdev
->inserted
&& bdev
->inserted
->encryption_key_missing
);
828 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
830 BlockInfoList
*bdev_list
, *bdev
;
833 bdev_list
= qmp_query_block(NULL
);
834 for (bdev
= bdev_list
; bdev
; bdev
= bdev
->next
) {
835 if (key_is_missing(bdev
->value
)) {
836 monitor_read_block_device_key(mon
, bdev
->value
->device
,
843 hmp_handle_error(mon
, &errp
);
846 qapi_free_BlockInfoList(bdev_list
);
849 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
851 qmp_system_wakeup(NULL
);
854 void hmp_inject_nmi(Monitor
*mon
, const QDict
*qdict
)
858 qmp_inject_nmi(&errp
);
859 hmp_handle_error(mon
, &errp
);
862 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
864 const char *name
= qdict_get_str(qdict
, "name");
865 int up
= qdict_get_bool(qdict
, "up");
868 qmp_set_link(name
, up
, &errp
);
869 hmp_handle_error(mon
, &errp
);
872 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
874 const char *device
= qdict_get_str(qdict
, "device");
875 const char *password
= qdict_get_str(qdict
, "password");
878 qmp_block_passwd(true, device
, false, NULL
, password
, &errp
);
879 hmp_handle_error(mon
, &errp
);
882 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
884 int64_t value
= qdict_get_int(qdict
, "value");
887 qmp_balloon(value
, &errp
);
889 monitor_printf(mon
, "balloon: %s\n", error_get_pretty(errp
));
894 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
896 const char *device
= qdict_get_str(qdict
, "device");
897 int64_t size
= qdict_get_int(qdict
, "size");
900 qmp_block_resize(true, device
, false, NULL
, size
, &errp
);
901 hmp_handle_error(mon
, &errp
);
904 void hmp_drive_mirror(Monitor
*mon
, const QDict
*qdict
)
906 const char *device
= qdict_get_str(qdict
, "device");
907 const char *filename
= qdict_get_str(qdict
, "target");
908 const char *format
= qdict_get_try_str(qdict
, "format");
909 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
910 int full
= qdict_get_try_bool(qdict
, "full", 0);
911 enum NewImageMode mode
;
915 error_set(&errp
, QERR_MISSING_PARAMETER
, "target");
916 hmp_handle_error(mon
, &errp
);
921 mode
= NEW_IMAGE_MODE_EXISTING
;
923 mode
= NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
926 qmp_drive_mirror(device
, filename
, !!format
, format
,
927 full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
928 true, mode
, false, 0, false, 0, false, 0,
929 false, 0, false, 0, &errp
);
930 hmp_handle_error(mon
, &errp
);
933 void hmp_drive_backup(Monitor
*mon
, const QDict
*qdict
)
935 const char *device
= qdict_get_str(qdict
, "device");
936 const char *filename
= qdict_get_str(qdict
, "target");
937 const char *format
= qdict_get_try_str(qdict
, "format");
938 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
939 int full
= qdict_get_try_bool(qdict
, "full", 0);
940 enum NewImageMode mode
;
944 error_set(&errp
, QERR_MISSING_PARAMETER
, "target");
945 hmp_handle_error(mon
, &errp
);
950 mode
= NEW_IMAGE_MODE_EXISTING
;
952 mode
= NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
955 qmp_drive_backup(device
, filename
, !!format
, format
,
956 full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
957 true, mode
, false, 0, false, 0, false, 0, &errp
);
958 hmp_handle_error(mon
, &errp
);
961 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
963 const char *device
= qdict_get_str(qdict
, "device");
964 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
965 const char *format
= qdict_get_try_str(qdict
, "format");
966 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
967 enum NewImageMode mode
;
971 /* In the future, if 'snapshot-file' is not specified, the snapshot
972 will be taken internally. Today it's actually required. */
973 error_set(&errp
, QERR_MISSING_PARAMETER
, "snapshot-file");
974 hmp_handle_error(mon
, &errp
);
978 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
979 qmp_blockdev_snapshot_sync(true, device
, false, NULL
,
980 filename
, false, NULL
,
983 hmp_handle_error(mon
, &errp
);
986 void hmp_snapshot_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
988 const char *device
= qdict_get_str(qdict
, "device");
989 const char *name
= qdict_get_str(qdict
, "name");
992 qmp_blockdev_snapshot_internal_sync(device
, name
, &errp
);
993 hmp_handle_error(mon
, &errp
);
996 void hmp_snapshot_delete_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
998 const char *device
= qdict_get_str(qdict
, "device");
999 const char *name
= qdict_get_str(qdict
, "name");
1000 const char *id
= qdict_get_try_str(qdict
, "id");
1003 qmp_blockdev_snapshot_delete_internal_sync(device
, !!id
, id
,
1005 hmp_handle_error(mon
, &errp
);
1008 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
1010 qmp_migrate_cancel(NULL
);
1013 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
1015 double value
= qdict_get_double(qdict
, "value");
1016 qmp_migrate_set_downtime(value
, NULL
);
1019 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
1021 int64_t value
= qdict_get_int(qdict
, "value");
1024 qmp_migrate_set_cache_size(value
, &err
);
1026 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
1032 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
1034 int64_t value
= qdict_get_int(qdict
, "value");
1035 qmp_migrate_set_speed(value
, NULL
);
1038 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
1040 const char *cap
= qdict_get_str(qdict
, "capability");
1041 bool state
= qdict_get_bool(qdict
, "state");
1043 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
1046 for (i
= 0; i
< MIGRATION_CAPABILITY_MAX
; i
++) {
1047 if (strcmp(cap
, MigrationCapability_lookup
[i
]) == 0) {
1048 caps
->value
= g_malloc0(sizeof(*caps
->value
));
1049 caps
->value
->capability
= i
;
1050 caps
->value
->state
= state
;
1052 qmp_migrate_set_capabilities(caps
, &err
);
1057 if (i
== MIGRATION_CAPABILITY_MAX
) {
1058 error_set(&err
, QERR_INVALID_PARAMETER
, cap
);
1061 qapi_free_MigrationCapabilityStatusList(caps
);
1064 monitor_printf(mon
, "migrate_set_capability: %s\n",
1065 error_get_pretty(err
));
1070 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
1072 const char *protocol
= qdict_get_str(qdict
, "protocol");
1073 const char *password
= qdict_get_str(qdict
, "password");
1074 const char *connected
= qdict_get_try_str(qdict
, "connected");
1077 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
1078 hmp_handle_error(mon
, &err
);
1081 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
1083 const char *protocol
= qdict_get_str(qdict
, "protocol");
1084 const char *whenstr
= qdict_get_str(qdict
, "time");
1087 qmp_expire_password(protocol
, whenstr
, &err
);
1088 hmp_handle_error(mon
, &err
);
1091 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
1093 int force
= qdict_get_try_bool(qdict
, "force", 0);
1094 const char *device
= qdict_get_str(qdict
, "device");
1097 qmp_eject(device
, true, force
, &err
);
1098 hmp_handle_error(mon
, &err
);
1101 static void hmp_change_read_arg(void *opaque
, const char *password
,
1102 void *readline_opaque
)
1104 qmp_change_vnc_password(password
, NULL
);
1105 monitor_read_command(opaque
, 1);
1108 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
1110 const char *device
= qdict_get_str(qdict
, "device");
1111 const char *target
= qdict_get_str(qdict
, "target");
1112 const char *arg
= qdict_get_try_str(qdict
, "arg");
1115 if (strcmp(device
, "vnc") == 0 &&
1116 (strcmp(target
, "passwd") == 0 ||
1117 strcmp(target
, "password") == 0)) {
1119 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
1124 qmp_change(device
, target
, !!arg
, arg
, &err
);
1126 error_get_class(err
) == ERROR_CLASS_DEVICE_ENCRYPTED
) {
1128 monitor_read_block_device_key(mon
, device
, NULL
, NULL
);
1131 hmp_handle_error(mon
, &err
);
1134 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
1138 qmp_block_set_io_throttle(qdict_get_str(qdict
, "device"),
1139 qdict_get_int(qdict
, "bps"),
1140 qdict_get_int(qdict
, "bps_rd"),
1141 qdict_get_int(qdict
, "bps_wr"),
1142 qdict_get_int(qdict
, "iops"),
1143 qdict_get_int(qdict
, "iops_rd"),
1144 qdict_get_int(qdict
, "iops_wr"),
1145 false, /* no burst max via HMP */
1157 false, /* No default I/O size */
1159 hmp_handle_error(mon
, &err
);
1162 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
1164 Error
*error
= NULL
;
1165 const char *device
= qdict_get_str(qdict
, "device");
1166 const char *base
= qdict_get_try_str(qdict
, "base");
1167 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
1169 qmp_block_stream(device
, base
!= NULL
, base
,
1170 qdict_haskey(qdict
, "speed"), speed
,
1171 true, BLOCKDEV_ON_ERROR_REPORT
, &error
);
1173 hmp_handle_error(mon
, &error
);
1176 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
1178 Error
*error
= NULL
;
1179 const char *device
= qdict_get_str(qdict
, "device");
1180 int64_t value
= qdict_get_int(qdict
, "speed");
1182 qmp_block_job_set_speed(device
, value
, &error
);
1184 hmp_handle_error(mon
, &error
);
1187 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
1189 Error
*error
= NULL
;
1190 const char *device
= qdict_get_str(qdict
, "device");
1191 bool force
= qdict_get_try_bool(qdict
, "force", 0);
1193 qmp_block_job_cancel(device
, true, force
, &error
);
1195 hmp_handle_error(mon
, &error
);
1198 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
1200 Error
*error
= NULL
;
1201 const char *device
= qdict_get_str(qdict
, "device");
1203 qmp_block_job_pause(device
, &error
);
1205 hmp_handle_error(mon
, &error
);
1208 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
1210 Error
*error
= NULL
;
1211 const char *device
= qdict_get_str(qdict
, "device");
1213 qmp_block_job_resume(device
, &error
);
1215 hmp_handle_error(mon
, &error
);
1218 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
1220 Error
*error
= NULL
;
1221 const char *device
= qdict_get_str(qdict
, "device");
1223 qmp_block_job_complete(device
, &error
);
1225 hmp_handle_error(mon
, &error
);
1228 typedef struct MigrationStatus
1232 bool is_block_migration
;
1235 static void hmp_migrate_status_cb(void *opaque
)
1237 MigrationStatus
*status
= opaque
;
1238 MigrationInfo
*info
;
1240 info
= qmp_query_migrate(NULL
);
1241 if (!info
->has_status
|| strcmp(info
->status
, "active") == 0 ||
1242 strcmp(info
->status
, "setup") == 0) {
1243 if (info
->has_disk
) {
1246 if (info
->disk
->remaining
) {
1247 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1252 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1253 monitor_flush(status
->mon
);
1256 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1000);
1258 if (status
->is_block_migration
) {
1259 monitor_printf(status
->mon
, "\n");
1261 monitor_resume(status
->mon
);
1262 timer_del(status
->timer
);
1266 qapi_free_MigrationInfo(info
);
1269 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1271 int detach
= qdict_get_try_bool(qdict
, "detach", 0);
1272 int blk
= qdict_get_try_bool(qdict
, "blk", 0);
1273 int inc
= qdict_get_try_bool(qdict
, "inc", 0);
1274 const char *uri
= qdict_get_str(qdict
, "uri");
1277 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
1279 monitor_printf(mon
, "migrate: %s\n", error_get_pretty(err
));
1285 MigrationStatus
*status
;
1287 if (monitor_suspend(mon
) < 0) {
1288 monitor_printf(mon
, "terminal does not allow synchronous "
1289 "migration, continuing detached\n");
1293 status
= g_malloc0(sizeof(*status
));
1295 status
->is_block_migration
= blk
|| inc
;
1296 status
->timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, hmp_migrate_status_cb
,
1298 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
1302 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1304 const char *id
= qdict_get_str(qdict
, "id");
1307 qmp_device_del(id
, &err
);
1308 hmp_handle_error(mon
, &err
);
1311 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1314 int paging
= qdict_get_try_bool(qdict
, "paging", 0);
1315 int zlib
= qdict_get_try_bool(qdict
, "zlib", 0);
1316 int lzo
= qdict_get_try_bool(qdict
, "lzo", 0);
1317 int snappy
= qdict_get_try_bool(qdict
, "snappy", 0);
1318 const char *file
= qdict_get_str(qdict
, "filename");
1319 bool has_begin
= qdict_haskey(qdict
, "begin");
1320 bool has_length
= qdict_haskey(qdict
, "length");
1323 enum DumpGuestMemoryFormat dump_format
= DUMP_GUEST_MEMORY_FORMAT_ELF
;
1326 if (zlib
+ lzo
+ snappy
> 1) {
1327 error_setg(&errp
, "only one of '-z|-l|-s' can be set");
1328 hmp_handle_error(mon
, &errp
);
1333 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB
;
1337 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO
;
1341 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY
;
1345 begin
= qdict_get_int(qdict
, "begin");
1348 length
= qdict_get_int(qdict
, "length");
1351 prot
= g_strconcat("file:", file
, NULL
);
1353 qmp_dump_guest_memory(paging
, prot
, has_begin
, begin
, has_length
, length
,
1354 true, dump_format
, &errp
);
1355 hmp_handle_error(mon
, &errp
);
1359 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
1364 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
1369 netdev_add(opts
, &err
);
1371 qemu_opts_del(opts
);
1375 hmp_handle_error(mon
, &err
);
1378 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
1380 const char *id
= qdict_get_str(qdict
, "id");
1383 qmp_netdev_del(id
, &err
);
1384 hmp_handle_error(mon
, &err
);
1387 void hmp_object_add(Monitor
*mon
, const QDict
*qdict
)
1397 opts
= qemu_opts_from_qdict(qemu_find_opts("object"), qdict
, &err
);
1402 ov
= opts_visitor_new(opts
);
1403 pdict
= qdict_clone_shallow(qdict
);
1405 visit_start_struct(opts_get_visitor(ov
), &dummy
, NULL
, NULL
, 0, &err
);
1410 qdict_del(pdict
, "qom-type");
1411 visit_type_str(opts_get_visitor(ov
), &type
, "qom-type", &err
);
1416 qdict_del(pdict
, "id");
1417 visit_type_str(opts_get_visitor(ov
), &id
, "id", &err
);
1422 object_add(type
, id
, pdict
, opts_get_visitor(ov
), &err
);
1426 visit_end_struct(opts_get_visitor(ov
), &err
);
1428 qmp_object_del(id
, NULL
);
1432 opts_visitor_cleanup(ov
);
1435 qemu_opts_del(opts
);
1441 hmp_handle_error(mon
, &err
);
1444 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
1446 const char *fdname
= qdict_get_str(qdict
, "fdname");
1449 qmp_getfd(fdname
, &errp
);
1450 hmp_handle_error(mon
, &errp
);
1453 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
1455 const char *fdname
= qdict_get_str(qdict
, "fdname");
1458 qmp_closefd(fdname
, &errp
);
1459 hmp_handle_error(mon
, &errp
);
1462 void hmp_send_key(Monitor
*mon
, const QDict
*qdict
)
1464 const char *keys
= qdict_get_str(qdict
, "keys");
1465 KeyValueList
*keylist
, *head
= NULL
, *tmp
= NULL
;
1466 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
1467 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
1469 char keyname_buf
[16];
1474 separator
= strchr(keys
, '-');
1475 keyname_len
= separator
? separator
- keys
: strlen(keys
);
1476 pstrcpy(keyname_buf
, sizeof(keyname_buf
), keys
);
1478 /* Be compatible with old interface, convert user inputted "<" */
1479 if (!strncmp(keyname_buf
, "<", 1) && keyname_len
== 1) {
1480 pstrcpy(keyname_buf
, sizeof(keyname_buf
), "less");
1483 keyname_buf
[keyname_len
] = 0;
1485 keylist
= g_malloc0(sizeof(*keylist
));
1486 keylist
->value
= g_malloc0(sizeof(*keylist
->value
));
1492 tmp
->next
= keylist
;
1496 if (strstart(keyname_buf
, "0x", NULL
)) {
1498 int value
= strtoul(keyname_buf
, &endp
, 0);
1499 if (*endp
!= '\0') {
1502 keylist
->value
->kind
= KEY_VALUE_KIND_NUMBER
;
1503 keylist
->value
->number
= value
;
1505 int idx
= index_from_key(keyname_buf
);
1506 if (idx
== Q_KEY_CODE_MAX
) {
1509 keylist
->value
->kind
= KEY_VALUE_KIND_QCODE
;
1510 keylist
->value
->qcode
= idx
;
1516 keys
= separator
+ 1;
1519 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
1520 hmp_handle_error(mon
, &err
);
1523 qapi_free_KeyValueList(head
);
1527 monitor_printf(mon
, "invalid parameter: %s\n", keyname_buf
);
1531 void hmp_screen_dump(Monitor
*mon
, const QDict
*qdict
)
1533 const char *filename
= qdict_get_str(qdict
, "filename");
1536 qmp_screendump(filename
, &err
);
1537 hmp_handle_error(mon
, &err
);
1540 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
1542 const char *uri
= qdict_get_str(qdict
, "uri");
1543 int writable
= qdict_get_try_bool(qdict
, "writable", 0);
1544 int all
= qdict_get_try_bool(qdict
, "all", 0);
1545 Error
*local_err
= NULL
;
1546 BlockInfoList
*block_list
, *info
;
1547 SocketAddress
*addr
;
1549 if (writable
&& !all
) {
1550 error_setg(&local_err
, "-w only valid together with -a");
1554 /* First check if the address is valid and start the server. */
1555 addr
= socket_parse(uri
, &local_err
);
1556 if (local_err
!= NULL
) {
1560 qmp_nbd_server_start(addr
, &local_err
);
1561 qapi_free_SocketAddress(addr
);
1562 if (local_err
!= NULL
) {
1570 /* Then try adding all block devices. If one fails, close all and
1573 block_list
= qmp_query_block(NULL
);
1575 for (info
= block_list
; info
; info
= info
->next
) {
1576 if (!info
->value
->has_inserted
) {
1580 qmp_nbd_server_add(info
->value
->device
, true, writable
, &local_err
);
1582 if (local_err
!= NULL
) {
1583 qmp_nbd_server_stop(NULL
);
1588 qapi_free_BlockInfoList(block_list
);
1591 hmp_handle_error(mon
, &local_err
);
1594 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
1596 const char *device
= qdict_get_str(qdict
, "device");
1597 int writable
= qdict_get_try_bool(qdict
, "writable", 0);
1598 Error
*local_err
= NULL
;
1600 qmp_nbd_server_add(device
, true, writable
, &local_err
);
1602 if (local_err
!= NULL
) {
1603 hmp_handle_error(mon
, &local_err
);
1607 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
1611 qmp_nbd_server_stop(&errp
);
1612 hmp_handle_error(mon
, &errp
);
1615 void hmp_cpu_add(Monitor
*mon
, const QDict
*qdict
)
1620 cpuid
= qdict_get_int(qdict
, "id");
1621 qmp_cpu_add(cpuid
, &err
);
1622 hmp_handle_error(mon
, &err
);
1625 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
1627 const char *args
= qdict_get_str(qdict
, "args");
1631 opts
= qemu_opts_parse(qemu_find_opts("chardev"), args
, 1);
1633 error_setg(&err
, "Parsing chardev args failed");
1635 qemu_chr_new_from_opts(opts
, NULL
, &err
);
1637 hmp_handle_error(mon
, &err
);
1640 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
1642 Error
*local_err
= NULL
;
1644 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
1645 hmp_handle_error(mon
, &local_err
);
1648 void hmp_qemu_io(Monitor
*mon
, const QDict
*qdict
)
1650 BlockDriverState
*bs
;
1651 const char* device
= qdict_get_str(qdict
, "device");
1652 const char* command
= qdict_get_str(qdict
, "command");
1655 bs
= bdrv_find(device
);
1657 qemuio_command(bs
, command
);
1659 error_set(&err
, QERR_DEVICE_NOT_FOUND
, device
);
1662 hmp_handle_error(mon
, &err
);
1665 void hmp_object_del(Monitor
*mon
, const QDict
*qdict
)
1667 const char *id
= qdict_get_str(qdict
, "id");
1670 qmp_object_del(id
, &err
);
1671 hmp_handle_error(mon
, &err
);