2 * Human Monitor Interface
4 * Copyright IBM, Corp. 2011
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
12 * Contributions after 2012-01-13 are licensed under the terms of the
13 * GNU GPL, version 2 or (at your option) any later version.
18 #include "sysemu/char.h"
19 #include "qemu/option.h"
20 #include "qemu/timer.h"
21 #include "qmp-commands.h"
22 #include "qemu/sockets.h"
23 #include "monitor/monitor.h"
24 #include "qapi/opts-visitor.h"
25 #include "qapi/string-output-visitor.h"
26 #include "qapi-visit.h"
27 #include "ui/console.h"
28 #include "block/qapi.h"
31 static void hmp_handle_error(Monitor
*mon
, Error
**errp
)
35 monitor_printf(mon
, "%s\n", error_get_pretty(*errp
));
40 void hmp_info_name(Monitor
*mon
, const QDict
*qdict
)
44 info
= qmp_query_name(NULL
);
46 monitor_printf(mon
, "%s\n", info
->name
);
48 qapi_free_NameInfo(info
);
51 void hmp_info_version(Monitor
*mon
, const QDict
*qdict
)
55 info
= qmp_query_version(NULL
);
57 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
58 info
->qemu
.major
, info
->qemu
.minor
, info
->qemu
.micro
,
61 qapi_free_VersionInfo(info
);
64 void hmp_info_kvm(Monitor
*mon
, const QDict
*qdict
)
68 info
= qmp_query_kvm(NULL
);
69 monitor_printf(mon
, "kvm support: ");
71 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
73 monitor_printf(mon
, "not compiled\n");
76 qapi_free_KvmInfo(info
);
79 void hmp_info_status(Monitor
*mon
, const QDict
*qdict
)
83 info
= qmp_query_status(NULL
);
85 monitor_printf(mon
, "VM status: %s%s",
86 info
->running
? "running" : "paused",
87 info
->singlestep
? " (single step mode)" : "");
89 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
90 monitor_printf(mon
, " (%s)", RunState_lookup
[info
->status
]);
93 monitor_printf(mon
, "\n");
95 qapi_free_StatusInfo(info
);
98 void hmp_info_uuid(Monitor
*mon
, const QDict
*qdict
)
102 info
= qmp_query_uuid(NULL
);
103 monitor_printf(mon
, "%s\n", info
->UUID
);
104 qapi_free_UuidInfo(info
);
107 void hmp_info_chardev(Monitor
*mon
, const QDict
*qdict
)
109 ChardevInfoList
*char_info
, *info
;
111 char_info
= qmp_query_chardev(NULL
);
112 for (info
= char_info
; info
; info
= info
->next
) {
113 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
114 info
->value
->filename
);
117 qapi_free_ChardevInfoList(char_info
);
120 void hmp_info_mice(Monitor
*mon
, const QDict
*qdict
)
122 MouseInfoList
*mice_list
, *mouse
;
124 mice_list
= qmp_query_mice(NULL
);
126 monitor_printf(mon
, "No mouse devices connected\n");
130 for (mouse
= mice_list
; mouse
; mouse
= mouse
->next
) {
131 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s%s\n",
132 mouse
->value
->current
? '*' : ' ',
133 mouse
->value
->index
, mouse
->value
->name
,
134 mouse
->value
->absolute
? " (absolute)" : "");
137 qapi_free_MouseInfoList(mice_list
);
140 void hmp_info_migrate(Monitor
*mon
, const QDict
*qdict
)
143 MigrationCapabilityStatusList
*caps
, *cap
;
145 info
= qmp_query_migrate(NULL
);
146 caps
= qmp_query_migrate_capabilities(NULL
);
148 /* do not display parameters during setup */
149 if (info
->has_status
&& caps
) {
150 monitor_printf(mon
, "capabilities: ");
151 for (cap
= caps
; cap
; cap
= cap
->next
) {
152 monitor_printf(mon
, "%s: %s ",
153 MigrationCapability_lookup
[cap
->value
->capability
],
154 cap
->value
->state
? "on" : "off");
156 monitor_printf(mon
, "\n");
159 if (info
->has_status
) {
160 monitor_printf(mon
, "Migration status: %s\n", info
->status
);
161 monitor_printf(mon
, "total time: %" PRIu64
" milliseconds\n",
163 if (info
->has_expected_downtime
) {
164 monitor_printf(mon
, "expected downtime: %" PRIu64
" milliseconds\n",
165 info
->expected_downtime
);
167 if (info
->has_downtime
) {
168 monitor_printf(mon
, "downtime: %" PRIu64
" milliseconds\n",
171 if (info
->has_setup_time
) {
172 monitor_printf(mon
, "setup: %" PRIu64
" milliseconds\n",
178 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
179 info
->ram
->transferred
>> 10);
180 monitor_printf(mon
, "throughput: %0.2f mbps\n",
182 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
183 info
->ram
->remaining
>> 10);
184 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
185 info
->ram
->total
>> 10);
186 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
187 info
->ram
->duplicate
);
188 monitor_printf(mon
, "skipped: %" PRIu64
" pages\n",
190 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
192 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
193 info
->ram
->normal_bytes
>> 10);
194 monitor_printf(mon
, "dirty sync count: %" PRIu64
"\n",
195 info
->ram
->dirty_sync_count
);
196 if (info
->ram
->dirty_pages_rate
) {
197 monitor_printf(mon
, "dirty pages rate: %" PRIu64
" pages\n",
198 info
->ram
->dirty_pages_rate
);
202 if (info
->has_disk
) {
203 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
204 info
->disk
->transferred
>> 10);
205 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
206 info
->disk
->remaining
>> 10);
207 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
208 info
->disk
->total
>> 10);
211 if (info
->has_xbzrle_cache
) {
212 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
213 info
->xbzrle_cache
->cache_size
);
214 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
215 info
->xbzrle_cache
->bytes
>> 10);
216 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
217 info
->xbzrle_cache
->pages
);
218 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
"\n",
219 info
->xbzrle_cache
->cache_miss
);
220 monitor_printf(mon
, "xbzrle cache miss rate: %0.2f\n",
221 info
->xbzrle_cache
->cache_miss_rate
);
222 monitor_printf(mon
, "xbzrle overflow : %" PRIu64
"\n",
223 info
->xbzrle_cache
->overflow
);
226 qapi_free_MigrationInfo(info
);
227 qapi_free_MigrationCapabilityStatusList(caps
);
230 void hmp_info_migrate_capabilities(Monitor
*mon
, const QDict
*qdict
)
232 MigrationCapabilityStatusList
*caps
, *cap
;
234 caps
= qmp_query_migrate_capabilities(NULL
);
237 monitor_printf(mon
, "capabilities: ");
238 for (cap
= caps
; cap
; cap
= cap
->next
) {
239 monitor_printf(mon
, "%s: %s ",
240 MigrationCapability_lookup
[cap
->value
->capability
],
241 cap
->value
->state
? "on" : "off");
243 monitor_printf(mon
, "\n");
246 qapi_free_MigrationCapabilityStatusList(caps
);
249 void hmp_info_migrate_cache_size(Monitor
*mon
, const QDict
*qdict
)
251 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
252 qmp_query_migrate_cache_size(NULL
) >> 10);
255 void hmp_info_cpus(Monitor
*mon
, const QDict
*qdict
)
257 CpuInfoList
*cpu_list
, *cpu
;
259 cpu_list
= qmp_query_cpus(NULL
);
261 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
264 if (cpu
->value
->CPU
== monitor_get_cpu_index()) {
268 monitor_printf(mon
, "%c CPU #%" PRId64
":", active
, cpu
->value
->CPU
);
270 if (cpu
->value
->has_pc
) {
271 monitor_printf(mon
, " pc=0x%016" PRIx64
, cpu
->value
->pc
);
273 if (cpu
->value
->has_nip
) {
274 monitor_printf(mon
, " nip=0x%016" PRIx64
, cpu
->value
->nip
);
276 if (cpu
->value
->has_npc
) {
277 monitor_printf(mon
, " npc=0x%016" PRIx64
, cpu
->value
->npc
);
279 if (cpu
->value
->has_PC
) {
280 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->PC
);
283 if (cpu
->value
->halted
) {
284 monitor_printf(mon
, " (halted)");
287 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
290 qapi_free_CpuInfoList(cpu_list
);
293 void hmp_info_block(Monitor
*mon
, const QDict
*qdict
)
295 BlockInfoList
*block_list
, *info
;
296 ImageInfo
*image_info
;
297 const char *device
= qdict_get_try_str(qdict
, "device");
298 bool verbose
= qdict_get_try_bool(qdict
, "verbose", 0);
300 block_list
= qmp_query_block(NULL
);
302 for (info
= block_list
; info
; info
= info
->next
) {
303 if (device
&& strcmp(device
, info
->value
->device
)) {
307 if (info
!= block_list
) {
308 monitor_printf(mon
, "\n");
311 monitor_printf(mon
, "%s", info
->value
->device
);
312 if (info
->value
->has_inserted
) {
313 monitor_printf(mon
, ": %s (%s%s%s)\n",
314 info
->value
->inserted
->file
,
315 info
->value
->inserted
->drv
,
316 info
->value
->inserted
->ro
? ", read-only" : "",
317 info
->value
->inserted
->encrypted
? ", encrypted" : "");
319 monitor_printf(mon
, ": [not inserted]\n");
322 if (info
->value
->has_io_status
&& info
->value
->io_status
!= BLOCK_DEVICE_IO_STATUS_OK
) {
323 monitor_printf(mon
, " I/O status: %s\n",
324 BlockDeviceIoStatus_lookup
[info
->value
->io_status
]);
327 if (info
->value
->removable
) {
328 monitor_printf(mon
, " Removable device: %slocked, tray %s\n",
329 info
->value
->locked
? "" : "not ",
330 info
->value
->tray_open
? "open" : "closed");
334 if (!info
->value
->has_inserted
) {
338 if (info
->value
->inserted
->has_backing_file
) {
341 "(chain depth: %" PRId64
")\n",
342 info
->value
->inserted
->backing_file
,
343 info
->value
->inserted
->backing_file_depth
);
346 if (info
->value
->inserted
->detect_zeroes
!= BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF
) {
347 monitor_printf(mon
, " Detect zeroes: %s\n",
348 BlockdevDetectZeroesOptions_lookup
[info
->value
->inserted
->detect_zeroes
]);
351 if (info
->value
->inserted
->bps
352 || info
->value
->inserted
->bps_rd
353 || info
->value
->inserted
->bps_wr
354 || info
->value
->inserted
->iops
355 || info
->value
->inserted
->iops_rd
356 || info
->value
->inserted
->iops_wr
)
358 monitor_printf(mon
, " I/O throttling: bps=%" PRId64
359 " bps_rd=%" PRId64
" bps_wr=%" PRId64
361 " bps_rd_max=%" PRId64
362 " bps_wr_max=%" PRId64
363 " iops=%" PRId64
" iops_rd=%" PRId64
366 " iops_rd_max=%" PRId64
367 " iops_wr_max=%" PRId64
368 " iops_size=%" PRId64
"\n",
369 info
->value
->inserted
->bps
,
370 info
->value
->inserted
->bps_rd
,
371 info
->value
->inserted
->bps_wr
,
372 info
->value
->inserted
->bps_max
,
373 info
->value
->inserted
->bps_rd_max
,
374 info
->value
->inserted
->bps_wr_max
,
375 info
->value
->inserted
->iops
,
376 info
->value
->inserted
->iops_rd
,
377 info
->value
->inserted
->iops_wr
,
378 info
->value
->inserted
->iops_max
,
379 info
->value
->inserted
->iops_rd_max
,
380 info
->value
->inserted
->iops_wr_max
,
381 info
->value
->inserted
->iops_size
);
385 monitor_printf(mon
, "\nImages:\n");
386 image_info
= info
->value
->inserted
->image
;
388 bdrv_image_info_dump((fprintf_function
)monitor_printf
,
390 if (image_info
->has_backing_image
) {
391 image_info
= image_info
->backing_image
;
399 qapi_free_BlockInfoList(block_list
);
402 void hmp_info_blockstats(Monitor
*mon
, const QDict
*qdict
)
404 BlockStatsList
*stats_list
, *stats
;
406 stats_list
= qmp_query_blockstats(NULL
);
408 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
409 if (!stats
->value
->has_device
) {
413 monitor_printf(mon
, "%s:", stats
->value
->device
);
414 monitor_printf(mon
, " rd_bytes=%" PRId64
416 " rd_operations=%" PRId64
417 " wr_operations=%" PRId64
418 " flush_operations=%" PRId64
419 " wr_total_time_ns=%" PRId64
420 " rd_total_time_ns=%" PRId64
421 " flush_total_time_ns=%" PRId64
423 stats
->value
->stats
->rd_bytes
,
424 stats
->value
->stats
->wr_bytes
,
425 stats
->value
->stats
->rd_operations
,
426 stats
->value
->stats
->wr_operations
,
427 stats
->value
->stats
->flush_operations
,
428 stats
->value
->stats
->wr_total_time_ns
,
429 stats
->value
->stats
->rd_total_time_ns
,
430 stats
->value
->stats
->flush_total_time_ns
);
433 qapi_free_BlockStatsList(stats_list
);
436 void hmp_info_vnc(Monitor
*mon
, const QDict
*qdict
)
440 VncClientInfoList
*client
;
442 info
= qmp_query_vnc(&err
);
444 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
449 if (!info
->enabled
) {
450 monitor_printf(mon
, "Server: disabled\n");
454 monitor_printf(mon
, "Server:\n");
455 if (info
->has_host
&& info
->has_service
) {
456 monitor_printf(mon
, " address: %s:%s\n", info
->host
, info
->service
);
458 if (info
->has_auth
) {
459 monitor_printf(mon
, " auth: %s\n", info
->auth
);
462 if (!info
->has_clients
|| info
->clients
== NULL
) {
463 monitor_printf(mon
, "Client: none\n");
465 for (client
= info
->clients
; client
; client
= client
->next
) {
466 monitor_printf(mon
, "Client:\n");
467 monitor_printf(mon
, " address: %s:%s\n",
468 client
->value
->host
, client
->value
->service
);
469 monitor_printf(mon
, " x509_dname: %s\n",
470 client
->value
->x509_dname
?
471 client
->value
->x509_dname
: "none");
472 monitor_printf(mon
, " username: %s\n",
473 client
->value
->has_sasl_username
?
474 client
->value
->sasl_username
: "none");
479 qapi_free_VncInfo(info
);
482 void hmp_info_spice(Monitor
*mon
, const QDict
*qdict
)
484 SpiceChannelList
*chan
;
487 info
= qmp_query_spice(NULL
);
489 if (!info
->enabled
) {
490 monitor_printf(mon
, "Server: disabled\n");
494 monitor_printf(mon
, "Server:\n");
495 if (info
->has_port
) {
496 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
497 info
->host
, info
->port
);
499 if (info
->has_tls_port
) {
500 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
501 info
->host
, info
->tls_port
);
503 monitor_printf(mon
, " migrated: %s\n",
504 info
->migrated
? "true" : "false");
505 monitor_printf(mon
, " auth: %s\n", info
->auth
);
506 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
507 monitor_printf(mon
, " mouse-mode: %s\n",
508 SpiceQueryMouseMode_lookup
[info
->mouse_mode
]);
510 if (!info
->has_channels
|| info
->channels
== NULL
) {
511 monitor_printf(mon
, "Channels: none\n");
513 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
514 monitor_printf(mon
, "Channel:\n");
515 monitor_printf(mon
, " address: %s:%s%s\n",
516 chan
->value
->host
, chan
->value
->port
,
517 chan
->value
->tls
? " [tls]" : "");
518 monitor_printf(mon
, " session: %" PRId64
"\n",
519 chan
->value
->connection_id
);
520 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
521 chan
->value
->channel_type
, chan
->value
->channel_id
);
526 qapi_free_SpiceInfo(info
);
529 void hmp_info_balloon(Monitor
*mon
, const QDict
*qdict
)
534 info
= qmp_query_balloon(&err
);
536 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
541 monitor_printf(mon
, "balloon: actual=%" PRId64
"\n", info
->actual
>> 20);
543 qapi_free_BalloonInfo(info
);
546 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
548 PciMemoryRegionList
*region
;
550 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
551 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
552 dev
->slot
, dev
->function
);
553 monitor_printf(mon
, " ");
555 if (dev
->class_info
.has_desc
) {
556 monitor_printf(mon
, "%s", dev
->class_info
.desc
);
558 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
.q_class
);
561 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
562 dev
->id
.vendor
, dev
->id
.device
);
565 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
568 if (dev
->has_pci_bridge
) {
569 monitor_printf(mon
, " BUS %" PRId64
".\n",
570 dev
->pci_bridge
->bus
.number
);
571 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
572 dev
->pci_bridge
->bus
.secondary
);
573 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
574 dev
->pci_bridge
->bus
.subordinate
);
576 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
577 dev
->pci_bridge
->bus
.io_range
->base
,
578 dev
->pci_bridge
->bus
.io_range
->limit
);
581 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
582 dev
->pci_bridge
->bus
.memory_range
->base
,
583 dev
->pci_bridge
->bus
.memory_range
->limit
);
585 monitor_printf(mon
, " prefetchable memory range "
586 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
587 dev
->pci_bridge
->bus
.prefetchable_range
->base
,
588 dev
->pci_bridge
->bus
.prefetchable_range
->limit
);
591 for (region
= dev
->regions
; region
; region
= region
->next
) {
594 addr
= region
->value
->address
;
595 size
= region
->value
->size
;
597 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
599 if (!strcmp(region
->value
->type
, "io")) {
600 monitor_printf(mon
, "I/O at 0x%04" PRIx64
601 " [0x%04" PRIx64
"].\n",
602 addr
, addr
+ size
- 1);
604 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
605 " [0x%08" PRIx64
"].\n",
606 region
->value
->mem_type_64
? 64 : 32,
607 region
->value
->prefetch
? " prefetchable" : "",
608 addr
, addr
+ size
- 1);
612 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
614 if (dev
->has_pci_bridge
) {
615 if (dev
->pci_bridge
->has_devices
) {
616 PciDeviceInfoList
*cdev
;
617 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
618 hmp_info_pci_device(mon
, cdev
->value
);
624 void hmp_info_pci(Monitor
*mon
, const QDict
*qdict
)
626 PciInfoList
*info_list
, *info
;
629 info_list
= qmp_query_pci(&err
);
631 monitor_printf(mon
, "PCI devices not supported\n");
636 for (info
= info_list
; info
; info
= info
->next
) {
637 PciDeviceInfoList
*dev
;
639 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
640 hmp_info_pci_device(mon
, dev
->value
);
644 qapi_free_PciInfoList(info_list
);
647 void hmp_info_block_jobs(Monitor
*mon
, const QDict
*qdict
)
649 BlockJobInfoList
*list
;
652 list
= qmp_query_block_jobs(&err
);
656 monitor_printf(mon
, "No active jobs\n");
661 if (strcmp(list
->value
->type
, "stream") == 0) {
662 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
663 " of %" PRId64
" bytes, speed limit %" PRId64
670 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
671 " of %" PRId64
" bytes, speed limit %" PRId64
683 void hmp_info_tpm(Monitor
*mon
, const QDict
*qdict
)
685 TPMInfoList
*info_list
, *info
;
688 TPMPassthroughOptions
*tpo
;
690 info_list
= qmp_query_tpm(&err
);
692 monitor_printf(mon
, "TPM device not supported\n");
698 monitor_printf(mon
, "TPM device:\n");
701 for (info
= info_list
; info
; info
= info
->next
) {
702 TPMInfo
*ti
= info
->value
;
703 monitor_printf(mon
, " tpm%d: model=%s\n",
704 c
, TpmModel_lookup
[ti
->model
]);
706 monitor_printf(mon
, " \\ %s: type=%s",
707 ti
->id
, TpmTypeOptionsKind_lookup
[ti
->options
->kind
]);
709 switch (ti
->options
->kind
) {
710 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH
:
711 tpo
= ti
->options
->passthrough
;
712 monitor_printf(mon
, "%s%s%s%s",
713 tpo
->has_path
? ",path=" : "",
714 tpo
->has_path
? tpo
->path
: "",
715 tpo
->has_cancel_path
? ",cancel-path=" : "",
716 tpo
->has_cancel_path
? tpo
->cancel_path
: "");
718 case TPM_TYPE_OPTIONS_KIND_MAX
:
721 monitor_printf(mon
, "\n");
724 qapi_free_TPMInfoList(info_list
);
727 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
729 monitor_suspend(mon
);
733 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
738 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
740 qmp_system_reset(NULL
);
743 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
745 qmp_system_powerdown(NULL
);
748 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
752 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
753 use it are converted to the QAPI */
754 cpu_index
= qdict_get_int(qdict
, "index");
755 if (monitor_set_cpu(cpu_index
) < 0) {
756 monitor_printf(mon
, "invalid CPU index\n");
760 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
762 uint32_t size
= qdict_get_int(qdict
, "size");
763 const char *filename
= qdict_get_str(qdict
, "filename");
764 uint64_t addr
= qdict_get_int(qdict
, "val");
767 qmp_memsave(addr
, size
, filename
, true, monitor_get_cpu_index(), &err
);
768 hmp_handle_error(mon
, &err
);
771 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
773 uint32_t size
= qdict_get_int(qdict
, "size");
774 const char *filename
= qdict_get_str(qdict
, "filename");
775 uint64_t addr
= qdict_get_int(qdict
, "val");
778 qmp_pmemsave(addr
, size
, filename
, &err
);
779 hmp_handle_error(mon
, &err
);
782 void hmp_ringbuf_write(Monitor
*mon
, const QDict
*qdict
)
784 const char *chardev
= qdict_get_str(qdict
, "device");
785 const char *data
= qdict_get_str(qdict
, "data");
788 qmp_ringbuf_write(chardev
, data
, false, 0, &err
);
790 hmp_handle_error(mon
, &err
);
793 void hmp_ringbuf_read(Monitor
*mon
, const QDict
*qdict
)
795 uint32_t size
= qdict_get_int(qdict
, "size");
796 const char *chardev
= qdict_get_str(qdict
, "device");
801 data
= qmp_ringbuf_read(chardev
, size
, false, 0, &err
);
803 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
808 for (i
= 0; data
[i
]; i
++) {
809 unsigned char ch
= data
[i
];
812 monitor_printf(mon
, "\\\\");
813 } else if ((ch
< 0x20 && ch
!= '\n' && ch
!= '\t') || ch
== 0x7F) {
814 monitor_printf(mon
, "\\u%04X", ch
);
816 monitor_printf(mon
, "%c", ch
);
820 monitor_printf(mon
, "\n");
824 static void hmp_cont_cb(void *opaque
, int err
)
831 static bool key_is_missing(const BlockInfo
*bdev
)
833 return (bdev
->inserted
&& bdev
->inserted
->encryption_key_missing
);
836 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
838 BlockInfoList
*bdev_list
, *bdev
;
841 bdev_list
= qmp_query_block(NULL
);
842 for (bdev
= bdev_list
; bdev
; bdev
= bdev
->next
) {
843 if (key_is_missing(bdev
->value
)) {
844 monitor_read_block_device_key(mon
, bdev
->value
->device
,
851 hmp_handle_error(mon
, &err
);
854 qapi_free_BlockInfoList(bdev_list
);
857 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
859 qmp_system_wakeup(NULL
);
862 void hmp_inject_nmi(Monitor
*mon
, const QDict
*qdict
)
866 qmp_inject_nmi(&err
);
867 hmp_handle_error(mon
, &err
);
870 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
872 const char *name
= qdict_get_str(qdict
, "name");
873 int up
= qdict_get_bool(qdict
, "up");
876 qmp_set_link(name
, up
, &err
);
877 hmp_handle_error(mon
, &err
);
880 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
882 const char *device
= qdict_get_str(qdict
, "device");
883 const char *password
= qdict_get_str(qdict
, "password");
886 qmp_block_passwd(true, device
, false, NULL
, password
, &err
);
887 hmp_handle_error(mon
, &err
);
890 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
892 int64_t value
= qdict_get_int(qdict
, "value");
895 qmp_balloon(value
, &err
);
897 monitor_printf(mon
, "balloon: %s\n", error_get_pretty(err
));
902 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
904 const char *device
= qdict_get_str(qdict
, "device");
905 int64_t size
= qdict_get_int(qdict
, "size");
908 qmp_block_resize(true, device
, false, NULL
, size
, &err
);
909 hmp_handle_error(mon
, &err
);
912 void hmp_drive_mirror(Monitor
*mon
, const QDict
*qdict
)
914 const char *device
= qdict_get_str(qdict
, "device");
915 const char *filename
= qdict_get_str(qdict
, "target");
916 const char *format
= qdict_get_try_str(qdict
, "format");
917 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
918 int full
= qdict_get_try_bool(qdict
, "full", 0);
919 enum NewImageMode mode
;
923 error_set(&err
, QERR_MISSING_PARAMETER
, "target");
924 hmp_handle_error(mon
, &err
);
929 mode
= NEW_IMAGE_MODE_EXISTING
;
931 mode
= NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
934 qmp_drive_mirror(device
, filename
, !!format
, format
,
935 full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
936 true, mode
, false, 0, false, 0, false, 0,
937 false, 0, false, 0, &err
);
938 hmp_handle_error(mon
, &err
);
941 void hmp_drive_backup(Monitor
*mon
, const QDict
*qdict
)
943 const char *device
= qdict_get_str(qdict
, "device");
944 const char *filename
= qdict_get_str(qdict
, "target");
945 const char *format
= qdict_get_try_str(qdict
, "format");
946 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
947 int full
= qdict_get_try_bool(qdict
, "full", 0);
948 enum NewImageMode mode
;
952 error_set(&err
, QERR_MISSING_PARAMETER
, "target");
953 hmp_handle_error(mon
, &err
);
958 mode
= NEW_IMAGE_MODE_EXISTING
;
960 mode
= NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
963 qmp_drive_backup(device
, filename
, !!format
, format
,
964 full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
965 true, mode
, false, 0, false, 0, false, 0, &err
);
966 hmp_handle_error(mon
, &err
);
969 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
971 const char *device
= qdict_get_str(qdict
, "device");
972 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
973 const char *format
= qdict_get_try_str(qdict
, "format");
974 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
975 enum NewImageMode mode
;
979 /* In the future, if 'snapshot-file' is not specified, the snapshot
980 will be taken internally. Today it's actually required. */
981 error_set(&err
, QERR_MISSING_PARAMETER
, "snapshot-file");
982 hmp_handle_error(mon
, &err
);
986 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
987 qmp_blockdev_snapshot_sync(true, device
, false, NULL
,
988 filename
, false, NULL
,
991 hmp_handle_error(mon
, &err
);
994 void hmp_snapshot_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
996 const char *device
= qdict_get_str(qdict
, "device");
997 const char *name
= qdict_get_str(qdict
, "name");
1000 qmp_blockdev_snapshot_internal_sync(device
, name
, &err
);
1001 hmp_handle_error(mon
, &err
);
1004 void hmp_snapshot_delete_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1006 const char *device
= qdict_get_str(qdict
, "device");
1007 const char *name
= qdict_get_str(qdict
, "name");
1008 const char *id
= qdict_get_try_str(qdict
, "id");
1011 qmp_blockdev_snapshot_delete_internal_sync(device
, !!id
, id
,
1013 hmp_handle_error(mon
, &err
);
1016 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
1018 qmp_migrate_cancel(NULL
);
1021 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
1023 double value
= qdict_get_double(qdict
, "value");
1024 qmp_migrate_set_downtime(value
, NULL
);
1027 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
1029 int64_t value
= qdict_get_int(qdict
, "value");
1032 qmp_migrate_set_cache_size(value
, &err
);
1034 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
1040 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
1042 int64_t value
= qdict_get_int(qdict
, "value");
1043 qmp_migrate_set_speed(value
, NULL
);
1046 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
1048 const char *cap
= qdict_get_str(qdict
, "capability");
1049 bool state
= qdict_get_bool(qdict
, "state");
1051 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
1054 for (i
= 0; i
< MIGRATION_CAPABILITY_MAX
; i
++) {
1055 if (strcmp(cap
, MigrationCapability_lookup
[i
]) == 0) {
1056 caps
->value
= g_malloc0(sizeof(*caps
->value
));
1057 caps
->value
->capability
= i
;
1058 caps
->value
->state
= state
;
1060 qmp_migrate_set_capabilities(caps
, &err
);
1065 if (i
== MIGRATION_CAPABILITY_MAX
) {
1066 error_set(&err
, QERR_INVALID_PARAMETER
, cap
);
1069 qapi_free_MigrationCapabilityStatusList(caps
);
1072 monitor_printf(mon
, "migrate_set_capability: %s\n",
1073 error_get_pretty(err
));
1078 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
1080 const char *protocol
= qdict_get_str(qdict
, "protocol");
1081 const char *password
= qdict_get_str(qdict
, "password");
1082 const char *connected
= qdict_get_try_str(qdict
, "connected");
1085 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
1086 hmp_handle_error(mon
, &err
);
1089 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
1091 const char *protocol
= qdict_get_str(qdict
, "protocol");
1092 const char *whenstr
= qdict_get_str(qdict
, "time");
1095 qmp_expire_password(protocol
, whenstr
, &err
);
1096 hmp_handle_error(mon
, &err
);
1099 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
1101 int force
= qdict_get_try_bool(qdict
, "force", 0);
1102 const char *device
= qdict_get_str(qdict
, "device");
1105 qmp_eject(device
, true, force
, &err
);
1106 hmp_handle_error(mon
, &err
);
1109 static void hmp_change_read_arg(void *opaque
, const char *password
,
1110 void *readline_opaque
)
1112 qmp_change_vnc_password(password
, NULL
);
1113 monitor_read_command(opaque
, 1);
1116 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
1118 const char *device
= qdict_get_str(qdict
, "device");
1119 const char *target
= qdict_get_str(qdict
, "target");
1120 const char *arg
= qdict_get_try_str(qdict
, "arg");
1123 if (strcmp(device
, "vnc") == 0 &&
1124 (strcmp(target
, "passwd") == 0 ||
1125 strcmp(target
, "password") == 0)) {
1127 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
1132 qmp_change(device
, target
, !!arg
, arg
, &err
);
1134 error_get_class(err
) == ERROR_CLASS_DEVICE_ENCRYPTED
) {
1136 monitor_read_block_device_key(mon
, device
, NULL
, NULL
);
1139 hmp_handle_error(mon
, &err
);
1142 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
1146 qmp_block_set_io_throttle(qdict_get_str(qdict
, "device"),
1147 qdict_get_int(qdict
, "bps"),
1148 qdict_get_int(qdict
, "bps_rd"),
1149 qdict_get_int(qdict
, "bps_wr"),
1150 qdict_get_int(qdict
, "iops"),
1151 qdict_get_int(qdict
, "iops_rd"),
1152 qdict_get_int(qdict
, "iops_wr"),
1153 false, /* no burst max via HMP */
1165 false, /* No default I/O size */
1167 hmp_handle_error(mon
, &err
);
1170 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
1172 Error
*error
= NULL
;
1173 const char *device
= qdict_get_str(qdict
, "device");
1174 const char *base
= qdict_get_try_str(qdict
, "base");
1175 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
1177 qmp_block_stream(device
, base
!= NULL
, base
,
1178 qdict_haskey(qdict
, "speed"), speed
,
1179 true, BLOCKDEV_ON_ERROR_REPORT
, &error
);
1181 hmp_handle_error(mon
, &error
);
1184 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
1186 Error
*error
= NULL
;
1187 const char *device
= qdict_get_str(qdict
, "device");
1188 int64_t value
= qdict_get_int(qdict
, "speed");
1190 qmp_block_job_set_speed(device
, value
, &error
);
1192 hmp_handle_error(mon
, &error
);
1195 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
1197 Error
*error
= NULL
;
1198 const char *device
= qdict_get_str(qdict
, "device");
1199 bool force
= qdict_get_try_bool(qdict
, "force", 0);
1201 qmp_block_job_cancel(device
, true, force
, &error
);
1203 hmp_handle_error(mon
, &error
);
1206 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
1208 Error
*error
= NULL
;
1209 const char *device
= qdict_get_str(qdict
, "device");
1211 qmp_block_job_pause(device
, &error
);
1213 hmp_handle_error(mon
, &error
);
1216 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
1218 Error
*error
= NULL
;
1219 const char *device
= qdict_get_str(qdict
, "device");
1221 qmp_block_job_resume(device
, &error
);
1223 hmp_handle_error(mon
, &error
);
1226 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
1228 Error
*error
= NULL
;
1229 const char *device
= qdict_get_str(qdict
, "device");
1231 qmp_block_job_complete(device
, &error
);
1233 hmp_handle_error(mon
, &error
);
1236 typedef struct MigrationStatus
1240 bool is_block_migration
;
1243 static void hmp_migrate_status_cb(void *opaque
)
1245 MigrationStatus
*status
= opaque
;
1246 MigrationInfo
*info
;
1248 info
= qmp_query_migrate(NULL
);
1249 if (!info
->has_status
|| strcmp(info
->status
, "active") == 0 ||
1250 strcmp(info
->status
, "setup") == 0) {
1251 if (info
->has_disk
) {
1254 if (info
->disk
->remaining
) {
1255 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1260 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1261 monitor_flush(status
->mon
);
1264 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1000);
1266 if (status
->is_block_migration
) {
1267 monitor_printf(status
->mon
, "\n");
1269 monitor_resume(status
->mon
);
1270 timer_del(status
->timer
);
1274 qapi_free_MigrationInfo(info
);
1277 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1279 int detach
= qdict_get_try_bool(qdict
, "detach", 0);
1280 int blk
= qdict_get_try_bool(qdict
, "blk", 0);
1281 int inc
= qdict_get_try_bool(qdict
, "inc", 0);
1282 const char *uri
= qdict_get_str(qdict
, "uri");
1285 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
1287 monitor_printf(mon
, "migrate: %s\n", error_get_pretty(err
));
1293 MigrationStatus
*status
;
1295 if (monitor_suspend(mon
) < 0) {
1296 monitor_printf(mon
, "terminal does not allow synchronous "
1297 "migration, continuing detached\n");
1301 status
= g_malloc0(sizeof(*status
));
1303 status
->is_block_migration
= blk
|| inc
;
1304 status
->timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, hmp_migrate_status_cb
,
1306 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
1310 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1312 const char *id
= qdict_get_str(qdict
, "id");
1315 qmp_device_del(id
, &err
);
1316 hmp_handle_error(mon
, &err
);
1319 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1322 int paging
= qdict_get_try_bool(qdict
, "paging", 0);
1323 int zlib
= qdict_get_try_bool(qdict
, "zlib", 0);
1324 int lzo
= qdict_get_try_bool(qdict
, "lzo", 0);
1325 int snappy
= qdict_get_try_bool(qdict
, "snappy", 0);
1326 const char *file
= qdict_get_str(qdict
, "filename");
1327 bool has_begin
= qdict_haskey(qdict
, "begin");
1328 bool has_length
= qdict_haskey(qdict
, "length");
1331 enum DumpGuestMemoryFormat dump_format
= DUMP_GUEST_MEMORY_FORMAT_ELF
;
1334 if (zlib
+ lzo
+ snappy
> 1) {
1335 error_setg(&err
, "only one of '-z|-l|-s' can be set");
1336 hmp_handle_error(mon
, &err
);
1341 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB
;
1345 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO
;
1349 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY
;
1353 begin
= qdict_get_int(qdict
, "begin");
1356 length
= qdict_get_int(qdict
, "length");
1359 prot
= g_strconcat("file:", file
, NULL
);
1361 qmp_dump_guest_memory(paging
, prot
, has_begin
, begin
, has_length
, length
,
1362 true, dump_format
, &err
);
1363 hmp_handle_error(mon
, &err
);
1367 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
1372 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
1377 netdev_add(opts
, &err
);
1379 qemu_opts_del(opts
);
1383 hmp_handle_error(mon
, &err
);
1386 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
1388 const char *id
= qdict_get_str(qdict
, "id");
1391 qmp_netdev_del(id
, &err
);
1392 hmp_handle_error(mon
, &err
);
1395 void hmp_object_add(Monitor
*mon
, const QDict
*qdict
)
1398 Error
*err_end
= NULL
;
1406 opts
= qemu_opts_from_qdict(qemu_find_opts("object"), qdict
, &err
);
1411 ov
= opts_visitor_new(opts
);
1412 pdict
= qdict_clone_shallow(qdict
);
1414 visit_start_struct(opts_get_visitor(ov
), &dummy
, NULL
, NULL
, 0, &err
);
1419 qdict_del(pdict
, "qom-type");
1420 visit_type_str(opts_get_visitor(ov
), &type
, "qom-type", &err
);
1425 qdict_del(pdict
, "id");
1426 visit_type_str(opts_get_visitor(ov
), &id
, "id", &err
);
1431 object_add(type
, id
, pdict
, opts_get_visitor(ov
), &err
);
1434 visit_end_struct(opts_get_visitor(ov
), &err_end
);
1435 if (!err
&& err_end
) {
1436 qmp_object_del(id
, NULL
);
1438 error_propagate(&err
, err_end
);
1440 opts_visitor_cleanup(ov
);
1443 qemu_opts_del(opts
);
1449 hmp_handle_error(mon
, &err
);
1452 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
1454 const char *fdname
= qdict_get_str(qdict
, "fdname");
1457 qmp_getfd(fdname
, &err
);
1458 hmp_handle_error(mon
, &err
);
1461 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
1463 const char *fdname
= qdict_get_str(qdict
, "fdname");
1466 qmp_closefd(fdname
, &err
);
1467 hmp_handle_error(mon
, &err
);
1470 void hmp_send_key(Monitor
*mon
, const QDict
*qdict
)
1472 const char *keys
= qdict_get_str(qdict
, "keys");
1473 KeyValueList
*keylist
, *head
= NULL
, *tmp
= NULL
;
1474 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
1475 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
1477 char keyname_buf
[16];
1482 separator
= strchr(keys
, '-');
1483 keyname_len
= separator
? separator
- keys
: strlen(keys
);
1484 pstrcpy(keyname_buf
, sizeof(keyname_buf
), keys
);
1486 /* Be compatible with old interface, convert user inputted "<" */
1487 if (!strncmp(keyname_buf
, "<", 1) && keyname_len
== 1) {
1488 pstrcpy(keyname_buf
, sizeof(keyname_buf
), "less");
1491 keyname_buf
[keyname_len
] = 0;
1493 keylist
= g_malloc0(sizeof(*keylist
));
1494 keylist
->value
= g_malloc0(sizeof(*keylist
->value
));
1500 tmp
->next
= keylist
;
1504 if (strstart(keyname_buf
, "0x", NULL
)) {
1506 int value
= strtoul(keyname_buf
, &endp
, 0);
1507 if (*endp
!= '\0') {
1510 keylist
->value
->kind
= KEY_VALUE_KIND_NUMBER
;
1511 keylist
->value
->number
= value
;
1513 int idx
= index_from_key(keyname_buf
);
1514 if (idx
== Q_KEY_CODE_MAX
) {
1517 keylist
->value
->kind
= KEY_VALUE_KIND_QCODE
;
1518 keylist
->value
->qcode
= idx
;
1524 keys
= separator
+ 1;
1527 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
1528 hmp_handle_error(mon
, &err
);
1531 qapi_free_KeyValueList(head
);
1535 monitor_printf(mon
, "invalid parameter: %s\n", keyname_buf
);
1539 void hmp_screen_dump(Monitor
*mon
, const QDict
*qdict
)
1541 const char *filename
= qdict_get_str(qdict
, "filename");
1544 qmp_screendump(filename
, &err
);
1545 hmp_handle_error(mon
, &err
);
1548 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
1550 const char *uri
= qdict_get_str(qdict
, "uri");
1551 int writable
= qdict_get_try_bool(qdict
, "writable", 0);
1552 int all
= qdict_get_try_bool(qdict
, "all", 0);
1553 Error
*local_err
= NULL
;
1554 BlockInfoList
*block_list
, *info
;
1555 SocketAddress
*addr
;
1557 if (writable
&& !all
) {
1558 error_setg(&local_err
, "-w only valid together with -a");
1562 /* First check if the address is valid and start the server. */
1563 addr
= socket_parse(uri
, &local_err
);
1564 if (local_err
!= NULL
) {
1568 qmp_nbd_server_start(addr
, &local_err
);
1569 qapi_free_SocketAddress(addr
);
1570 if (local_err
!= NULL
) {
1578 /* Then try adding all block devices. If one fails, close all and
1581 block_list
= qmp_query_block(NULL
);
1583 for (info
= block_list
; info
; info
= info
->next
) {
1584 if (!info
->value
->has_inserted
) {
1588 qmp_nbd_server_add(info
->value
->device
, true, writable
, &local_err
);
1590 if (local_err
!= NULL
) {
1591 qmp_nbd_server_stop(NULL
);
1596 qapi_free_BlockInfoList(block_list
);
1599 hmp_handle_error(mon
, &local_err
);
1602 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
1604 const char *device
= qdict_get_str(qdict
, "device");
1605 int writable
= qdict_get_try_bool(qdict
, "writable", 0);
1606 Error
*local_err
= NULL
;
1608 qmp_nbd_server_add(device
, true, writable
, &local_err
);
1610 if (local_err
!= NULL
) {
1611 hmp_handle_error(mon
, &local_err
);
1615 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
1619 qmp_nbd_server_stop(&err
);
1620 hmp_handle_error(mon
, &err
);
1623 void hmp_cpu_add(Monitor
*mon
, const QDict
*qdict
)
1628 cpuid
= qdict_get_int(qdict
, "id");
1629 qmp_cpu_add(cpuid
, &err
);
1630 hmp_handle_error(mon
, &err
);
1633 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
1635 const char *args
= qdict_get_str(qdict
, "args");
1639 opts
= qemu_opts_parse(qemu_find_opts("chardev"), args
, 1);
1641 error_setg(&err
, "Parsing chardev args failed");
1643 qemu_chr_new_from_opts(opts
, NULL
, &err
);
1645 hmp_handle_error(mon
, &err
);
1648 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
1650 Error
*local_err
= NULL
;
1652 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
1653 hmp_handle_error(mon
, &local_err
);
1656 void hmp_qemu_io(Monitor
*mon
, const QDict
*qdict
)
1658 BlockDriverState
*bs
;
1659 const char* device
= qdict_get_str(qdict
, "device");
1660 const char* command
= qdict_get_str(qdict
, "command");
1663 bs
= bdrv_find(device
);
1665 qemuio_command(bs
, command
);
1667 error_set(&err
, QERR_DEVICE_NOT_FOUND
, device
);
1670 hmp_handle_error(mon
, &err
);
1673 void hmp_object_del(Monitor
*mon
, const QDict
*qdict
)
1675 const char *id
= qdict_get_str(qdict
, "id");
1678 qmp_object_del(id
, &err
);
1679 hmp_handle_error(mon
, &err
);
1682 void hmp_info_memdev(Monitor
*mon
, const QDict
*qdict
)
1685 MemdevList
*memdev_list
= qmp_query_memdev(&err
);
1686 MemdevList
*m
= memdev_list
;
1687 StringOutputVisitor
*ov
;
1692 ov
= string_output_visitor_new(false);
1693 visit_type_uint16List(string_output_get_visitor(ov
),
1694 &m
->value
->host_nodes
, NULL
, NULL
);
1695 monitor_printf(mon
, "memory backend: %d\n", i
);
1696 monitor_printf(mon
, " size: %" PRId64
"\n", m
->value
->size
);
1697 monitor_printf(mon
, " merge: %s\n",
1698 m
->value
->merge
? "true" : "false");
1699 monitor_printf(mon
, " dump: %s\n",
1700 m
->value
->dump
? "true" : "false");
1701 monitor_printf(mon
, " prealloc: %s\n",
1702 m
->value
->prealloc
? "true" : "false");
1703 monitor_printf(mon
, " policy: %s\n",
1704 HostMemPolicy_lookup
[m
->value
->policy
]);
1705 monitor_printf(mon
, " host nodes: %s\n",
1706 string_output_get_string(ov
));
1708 string_output_visitor_cleanup(ov
);
1713 monitor_printf(mon
, "\n");