2 * Blockdev HMP commands
5 * Anthony Liguori <aliguori@us.ibm.com>
7 * Copyright (c) 2003-2008 Fabrice Bellard
9 * This work is licensed under the terms of the GNU GPL, version 2.
10 * See the COPYING file in the top-level directory.
11 * Contributions after 2012-01-13 are licensed under the terms of the
12 * GNU GPL, version 2 or (at your option) any later version.
14 * This file incorporates work covered by the following copyright and
17 * Copyright (c) 2003-2008 Fabrice Bellard
19 * Permission is hereby granted, free of charge, to any person obtaining a copy
20 * of this software and associated documentation files (the "Software"), to deal
21 * in the Software without restriction, including without limitation the rights
22 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 * copies of the Software, and to permit persons to whom the Software is
24 * furnished to do so, subject to the following conditions:
26 * The above copyright notice and this permission notice shall be included in
27 * all copies or substantial portions of the Software.
29 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
32 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
38 #include "qemu/osdep.h"
39 #include "hw/boards.h"
40 #include "sysemu/block-backend.h"
41 #include "sysemu/blockdev.h"
42 #include "qapi/qapi-commands-block.h"
43 #include "qapi/qapi-commands-block-export.h"
44 #include "qapi/qmp/qdict.h"
45 #include "qapi/error.h"
46 #include "qapi/qmp/qerror.h"
47 #include "qemu/config-file.h"
48 #include "qemu/option.h"
49 #include "qemu/sockets.h"
50 #include "qemu/cutils.h"
51 #include "sysemu/sysemu.h"
52 #include "monitor/monitor.h"
53 #include "monitor/hmp.h"
54 #include "block/nbd.h"
55 #include "block/qapi.h"
56 #include "block/block_int.h"
57 #include "block/block-hmp-cmds.h"
60 static void hmp_drive_add_node(Monitor
*mon
, const char *optstr
)
64 Error
*local_err
= NULL
;
66 opts
= qemu_opts_parse_noisily(&qemu_drive_opts
, optstr
, false);
71 qdict
= qemu_opts_to_qdict(opts
, NULL
);
73 if (!qdict_get_try_str(qdict
, "node-name")) {
75 error_report("'node-name' needs to be specified");
79 BlockDriverState
*bs
= bds_tree_init(qdict
, &local_err
);
81 error_report_err(local_err
);
85 bdrv_set_monitor_owned(bs
);
90 void hmp_drive_add(Monitor
*mon
, const QDict
*qdict
)
96 const char *optstr
= qdict_get_str(qdict
, "opts");
97 bool node
= qdict_get_try_bool(qdict
, "node", false);
100 hmp_drive_add_node(mon
, optstr
);
104 opts
= drive_def(optstr
);
108 mc
= MACHINE_GET_CLASS(current_machine
);
109 dinfo
= drive_new(opts
, mc
->block_default_type
, &err
);
111 error_report_err(err
);
120 switch (dinfo
->type
) {
122 monitor_printf(mon
, "OK\n");
125 monitor_printf(mon
, "Can't hot-add drive to type %d\n", dinfo
->type
);
132 BlockBackend
*blk
= blk_by_legacy_dinfo(dinfo
);
133 monitor_remove_blk(blk
);
138 void hmp_drive_del(Monitor
*mon
, const QDict
*qdict
)
140 const char *id
= qdict_get_str(qdict
, "id");
142 BlockDriverState
*bs
;
143 AioContext
*aio_context
;
144 Error
*local_err
= NULL
;
146 bs
= bdrv_find_node(id
);
148 qmp_blockdev_del(id
, &local_err
);
150 error_report_err(local_err
);
155 blk
= blk_by_name(id
);
157 error_report("Device '%s' not found", id
);
161 if (!blk_legacy_dinfo(blk
)) {
162 error_report("Deleting device added with blockdev-add"
163 " is not supported");
167 aio_context
= blk_get_aio_context(blk
);
168 aio_context_acquire(aio_context
);
172 if (bdrv_op_is_blocked(bs
, BLOCK_OP_TYPE_DRIVE_DEL
, &local_err
)) {
173 error_report_err(local_err
);
174 aio_context_release(aio_context
);
181 /* Make the BlockBackend and the attached BlockDriverState anonymous */
182 monitor_remove_blk(blk
);
185 * If this BlockBackend has a device attached to it, its refcount will be
186 * decremented when the device is removed; otherwise we have to do so here.
188 if (blk_get_attached_dev(blk
)) {
189 /* Further I/O must not pause the guest */
190 blk_set_on_error(blk
, BLOCKDEV_ON_ERROR_REPORT
,
191 BLOCKDEV_ON_ERROR_REPORT
);
196 aio_context_release(aio_context
);
199 void hmp_commit(Monitor
*mon
, const QDict
*qdict
)
201 const char *device
= qdict_get_str(qdict
, "device");
205 if (!strcmp(device
, "all")) {
206 ret
= blk_commit_all();
208 BlockDriverState
*bs
;
209 AioContext
*aio_context
;
211 blk
= blk_by_name(device
);
213 error_report("Device '%s' not found", device
);
216 if (!blk_is_available(blk
)) {
217 error_report("Device '%s' has no medium", device
);
221 bs
= bdrv_skip_implicit_filters(blk_bs(blk
));
222 aio_context
= bdrv_get_aio_context(bs
);
223 aio_context_acquire(aio_context
);
225 ret
= bdrv_commit(bs
);
227 aio_context_release(aio_context
);
230 error_report("'commit' error for '%s': %s", device
, strerror(-ret
));
234 void hmp_drive_mirror(Monitor
*mon
, const QDict
*qdict
)
236 const char *filename
= qdict_get_str(qdict
, "target");
237 const char *format
= qdict_get_try_str(qdict
, "format");
238 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
239 bool full
= qdict_get_try_bool(qdict
, "full", false);
241 DriveMirror mirror
= {
242 .device
= (char *)qdict_get_str(qdict
, "device"),
243 .target
= (char *)filename
,
244 .has_format
= !!format
,
245 .format
= (char *)format
,
246 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
248 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
253 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
254 hmp_handle_error(mon
, err
);
257 qmp_drive_mirror(&mirror
, &err
);
258 hmp_handle_error(mon
, err
);
261 void hmp_drive_backup(Monitor
*mon
, const QDict
*qdict
)
263 const char *device
= qdict_get_str(qdict
, "device");
264 const char *filename
= qdict_get_str(qdict
, "target");
265 const char *format
= qdict_get_try_str(qdict
, "format");
266 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
267 bool full
= qdict_get_try_bool(qdict
, "full", false);
268 bool compress
= qdict_get_try_bool(qdict
, "compress", false);
270 DriveBackup backup
= {
271 .device
= (char *)device
,
272 .target
= (char *)filename
,
273 .has_format
= !!format
,
274 .format
= (char *)format
,
275 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
277 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
278 .has_compress
= !!compress
,
279 .compress
= compress
,
283 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
284 hmp_handle_error(mon
, err
);
288 qmp_drive_backup(&backup
, &err
);
289 hmp_handle_error(mon
, err
);
292 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
295 const char *device
= qdict_get_str(qdict
, "device");
296 int64_t value
= qdict_get_int(qdict
, "speed");
298 qmp_block_job_set_speed(device
, value
, &error
);
300 hmp_handle_error(mon
, error
);
303 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
306 const char *device
= qdict_get_str(qdict
, "device");
307 bool force
= qdict_get_try_bool(qdict
, "force", false);
309 qmp_block_job_cancel(device
, true, force
, &error
);
311 hmp_handle_error(mon
, error
);
314 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
317 const char *device
= qdict_get_str(qdict
, "device");
319 qmp_block_job_pause(device
, &error
);
321 hmp_handle_error(mon
, error
);
324 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
327 const char *device
= qdict_get_str(qdict
, "device");
329 qmp_block_job_resume(device
, &error
);
331 hmp_handle_error(mon
, error
);
334 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
337 const char *device
= qdict_get_str(qdict
, "device");
339 qmp_block_job_complete(device
, &error
);
341 hmp_handle_error(mon
, error
);
344 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
346 const char *device
= qdict_get_str(qdict
, "device");
347 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
348 const char *format
= qdict_get_try_str(qdict
, "format");
349 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
350 enum NewImageMode mode
;
355 * In the future, if 'snapshot-file' is not specified, the snapshot
356 * will be taken internally. Today it's actually required.
358 error_setg(&err
, QERR_MISSING_PARAMETER
, "snapshot-file");
359 hmp_handle_error(mon
, err
);
363 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
364 qmp_blockdev_snapshot_sync(true, device
, false, NULL
,
365 filename
, false, NULL
,
368 hmp_handle_error(mon
, err
);
371 void hmp_snapshot_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
373 const char *device
= qdict_get_str(qdict
, "device");
374 const char *name
= qdict_get_str(qdict
, "name");
377 qmp_blockdev_snapshot_internal_sync(device
, name
, &err
);
378 hmp_handle_error(mon
, err
);
381 void hmp_snapshot_delete_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
383 const char *device
= qdict_get_str(qdict
, "device");
384 const char *name
= qdict_get_str(qdict
, "name");
385 const char *id
= qdict_get_try_str(qdict
, "id");
388 qmp_blockdev_snapshot_delete_internal_sync(device
, !!id
, id
,
390 hmp_handle_error(mon
, err
);
393 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
395 const char *uri
= qdict_get_str(qdict
, "uri");
396 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
397 bool all
= qdict_get_try_bool(qdict
, "all", false);
398 Error
*local_err
= NULL
;
399 BlockInfoList
*block_list
, *info
;
401 NbdServerAddOptions export
;
403 if (writable
&& !all
) {
404 error_setg(&local_err
, "-w only valid together with -a");
408 /* First check if the address is valid and start the server. */
409 addr
= socket_parse(uri
, &local_err
);
410 if (local_err
!= NULL
) {
414 nbd_server_start(addr
, NULL
, NULL
, 0, &local_err
);
415 qapi_free_SocketAddress(addr
);
416 if (local_err
!= NULL
) {
424 /* Then try adding all block devices. If one fails, close all and
427 block_list
= qmp_query_block(NULL
);
429 for (info
= block_list
; info
; info
= info
->next
) {
430 if (!info
->value
->has_inserted
) {
434 export
= (NbdServerAddOptions
) {
435 .device
= info
->value
->device
,
436 .has_writable
= true,
437 .writable
= writable
,
440 qmp_nbd_server_add(&export
, &local_err
);
442 if (local_err
!= NULL
) {
443 qmp_nbd_server_stop(NULL
);
448 qapi_free_BlockInfoList(block_list
);
451 hmp_handle_error(mon
, local_err
);
454 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
456 const char *device
= qdict_get_str(qdict
, "device");
457 const char *name
= qdict_get_try_str(qdict
, "name");
458 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
459 Error
*local_err
= NULL
;
461 NbdServerAddOptions export
= {
462 .device
= (char *) device
,
464 .name
= (char *) name
,
465 .has_writable
= true,
466 .writable
= writable
,
469 qmp_nbd_server_add(&export
, &local_err
);
470 hmp_handle_error(mon
, local_err
);
473 void hmp_nbd_server_remove(Monitor
*mon
, const QDict
*qdict
)
475 const char *name
= qdict_get_str(qdict
, "name");
476 bool force
= qdict_get_try_bool(qdict
, "force", false);
479 /* Rely on BLOCK_EXPORT_REMOVE_MODE_SAFE being the default */
480 qmp_nbd_server_remove(name
, force
, BLOCK_EXPORT_REMOVE_MODE_HARD
, &err
);
481 hmp_handle_error(mon
, err
);
484 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
488 qmp_nbd_server_stop(&err
);
489 hmp_handle_error(mon
, err
);
492 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
494 const char *device
= qdict_get_str(qdict
, "device");
495 int64_t size
= qdict_get_int(qdict
, "size");
498 qmp_block_resize(true, device
, false, NULL
, size
, &err
);
499 hmp_handle_error(mon
, err
);
502 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
505 const char *device
= qdict_get_str(qdict
, "device");
506 const char *base
= qdict_get_try_str(qdict
, "base");
507 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
509 qmp_block_stream(true, device
, device
, base
!= NULL
, base
, false, NULL
,
510 false, NULL
, false, NULL
,
511 qdict_haskey(qdict
, "speed"), speed
, true,
512 BLOCKDEV_ON_ERROR_REPORT
, false, NULL
, false, false, false,
515 hmp_handle_error(mon
, error
);
518 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
521 char *device
= (char *) qdict_get_str(qdict
, "device");
522 BlockIOThrottle throttle
= {
523 .bps
= qdict_get_int(qdict
, "bps"),
524 .bps_rd
= qdict_get_int(qdict
, "bps_rd"),
525 .bps_wr
= qdict_get_int(qdict
, "bps_wr"),
526 .iops
= qdict_get_int(qdict
, "iops"),
527 .iops_rd
= qdict_get_int(qdict
, "iops_rd"),
528 .iops_wr
= qdict_get_int(qdict
, "iops_wr"),
532 * qmp_block_set_io_throttle has separate parameters for the
533 * (deprecated) block device name and the qdev ID but the HMP
534 * version has only one, so we must decide which one to pass.
536 if (blk_by_name(device
)) {
537 throttle
.has_device
= true;
538 throttle
.device
= device
;
540 throttle
.has_id
= true;
541 throttle
.id
= device
;
544 qmp_block_set_io_throttle(&throttle
, &err
);
545 hmp_handle_error(mon
, err
);
548 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
550 bool force
= qdict_get_try_bool(qdict
, "force", false);
551 const char *device
= qdict_get_str(qdict
, "device");
554 qmp_eject(true, device
, false, NULL
, true, force
, &err
);
555 hmp_handle_error(mon
, err
);
558 void hmp_qemu_io(Monitor
*mon
, const QDict
*qdict
)
561 BlockBackend
*local_blk
= NULL
;
562 bool qdev
= qdict_get_try_bool(qdict
, "qdev", false);
563 const char *device
= qdict_get_str(qdict
, "device");
564 const char *command
= qdict_get_str(qdict
, "command");
569 blk
= blk_by_qdev_id(device
, &err
);
574 blk
= blk_by_name(device
);
576 BlockDriverState
*bs
= bdrv_lookup_bs(NULL
, device
, &err
);
578 blk
= local_blk
= blk_new(bdrv_get_aio_context(bs
),
580 ret
= blk_insert_bs(blk
, bs
, &err
);
591 * Notably absent: Proper permission management. This is sad, but it seems
592 * almost impossible to achieve without changing the semantics and thereby
593 * limiting the use cases of the qemu-io HMP command.
595 * In an ideal world we would unconditionally create a new BlockBackend for
596 * qemuio_command(), but we have commands like 'reopen' and want them to
597 * take effect on the exact BlockBackend whose name the user passed instead
598 * of just on a temporary copy of it.
600 * Another problem is that deleting the temporary BlockBackend involves
601 * draining all requests on it first, but some qemu-iotests cases want to
602 * issue multiple aio_read/write requests and expect them to complete in
603 * the background while the monitor has already returned.
605 * This is also what prevents us from saving the original permissions and
606 * restoring them later: We can't revoke permissions until all requests
607 * have completed, and we don't know when that is nor can we really let
608 * anything else run before we have revoken them to avoid race conditions.
610 * What happens now is that command() in qemu-io-cmds.c can extend the
611 * permissions if necessary for the qemu-io command. And they simply stay
612 * extended, possibly resulting in a read-only guest device keeping write
613 * permissions. Ugly, but it appears to be the lesser evil.
615 qemuio_command(blk
, command
);
618 blk_unref(local_blk
);
619 hmp_handle_error(mon
, err
);
622 static void print_block_info(Monitor
*mon
, BlockInfo
*info
,
623 BlockDeviceInfo
*inserted
, bool verbose
)
625 ImageInfo
*image_info
;
627 assert(!info
|| !info
->has_inserted
|| info
->inserted
== inserted
);
629 if (info
&& *info
->device
) {
630 monitor_printf(mon
, "%s", info
->device
);
631 if (inserted
&& inserted
->has_node_name
) {
632 monitor_printf(mon
, " (%s)", inserted
->node_name
);
635 assert(info
|| inserted
);
636 monitor_printf(mon
, "%s",
637 inserted
&& inserted
->has_node_name
? inserted
->node_name
638 : info
&& info
->has_qdev
? info
->qdev
643 monitor_printf(mon
, ": %s (%s%s%s)\n",
646 inserted
->ro
? ", read-only" : "",
647 inserted
->encrypted
? ", encrypted" : "");
649 monitor_printf(mon
, ": [not inserted]\n");
653 if (info
->has_qdev
) {
654 monitor_printf(mon
, " Attached to: %s\n", info
->qdev
);
656 if (info
->has_io_status
&& info
->io_status
!= BLOCK_DEVICE_IO_STATUS_OK
) {
657 monitor_printf(mon
, " I/O status: %s\n",
658 BlockDeviceIoStatus_str(info
->io_status
));
661 if (info
->removable
) {
662 monitor_printf(mon
, " Removable device: %slocked, tray %s\n",
663 info
->locked
? "" : "not ",
664 info
->tray_open
? "open" : "closed");
673 monitor_printf(mon
, " Cache mode: %s%s%s\n",
674 inserted
->cache
->writeback
? "writeback" : "writethrough",
675 inserted
->cache
->direct
? ", direct" : "",
676 inserted
->cache
->no_flush
? ", ignore flushes" : "");
678 if (inserted
->has_backing_file
) {
681 "(chain depth: %" PRId64
")\n",
682 inserted
->backing_file
,
683 inserted
->backing_file_depth
);
686 if (inserted
->detect_zeroes
!= BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF
) {
687 monitor_printf(mon
, " Detect zeroes: %s\n",
688 BlockdevDetectZeroesOptions_str(inserted
->detect_zeroes
));
691 if (inserted
->bps
|| inserted
->bps_rd
|| inserted
->bps_wr
||
692 inserted
->iops
|| inserted
->iops_rd
|| inserted
->iops_wr
)
694 monitor_printf(mon
, " I/O throttling: bps=%" PRId64
695 " bps_rd=%" PRId64
" bps_wr=%" PRId64
697 " bps_rd_max=%" PRId64
698 " bps_wr_max=%" PRId64
699 " iops=%" PRId64
" iops_rd=%" PRId64
702 " iops_rd_max=%" PRId64
703 " iops_wr_max=%" PRId64
704 " iops_size=%" PRId64
710 inserted
->bps_rd_max
,
711 inserted
->bps_wr_max
,
716 inserted
->iops_rd_max
,
717 inserted
->iops_wr_max
,
723 monitor_printf(mon
, "\nImages:\n");
724 image_info
= inserted
->image
;
726 bdrv_image_info_dump(image_info
);
727 if (image_info
->has_backing_image
) {
728 image_info
= image_info
->backing_image
;
736 void hmp_info_block(Monitor
*mon
, const QDict
*qdict
)
738 BlockInfoList
*block_list
, *info
;
739 BlockDeviceInfoList
*blockdev_list
, *blockdev
;
740 const char *device
= qdict_get_try_str(qdict
, "device");
741 bool verbose
= qdict_get_try_bool(qdict
, "verbose", false);
742 bool nodes
= qdict_get_try_bool(qdict
, "nodes", false);
743 bool printed
= false;
745 /* Print BlockBackend information */
747 block_list
= qmp_query_block(NULL
);
752 for (info
= block_list
; info
; info
= info
->next
) {
753 if (device
&& strcmp(device
, info
->value
->device
)) {
757 if (info
!= block_list
) {
758 monitor_printf(mon
, "\n");
761 print_block_info(mon
, info
->value
, info
->value
->has_inserted
762 ? info
->value
->inserted
: NULL
,
767 qapi_free_BlockInfoList(block_list
);
769 if ((!device
&& !nodes
) || printed
) {
773 /* Print node information */
774 blockdev_list
= qmp_query_named_block_nodes(false, false, NULL
);
775 for (blockdev
= blockdev_list
; blockdev
; blockdev
= blockdev
->next
) {
776 assert(blockdev
->value
->has_node_name
);
777 if (device
&& strcmp(device
, blockdev
->value
->node_name
)) {
781 if (blockdev
!= blockdev_list
) {
782 monitor_printf(mon
, "\n");
785 print_block_info(mon
, NULL
, blockdev
->value
, verbose
);
787 qapi_free_BlockDeviceInfoList(blockdev_list
);
790 void hmp_info_blockstats(Monitor
*mon
, const QDict
*qdict
)
792 BlockStatsList
*stats_list
, *stats
;
794 stats_list
= qmp_query_blockstats(false, false, NULL
);
796 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
797 if (!stats
->value
->has_device
) {
801 monitor_printf(mon
, "%s:", stats
->value
->device
);
802 monitor_printf(mon
, " rd_bytes=%" PRId64
804 " rd_operations=%" PRId64
805 " wr_operations=%" PRId64
806 " flush_operations=%" PRId64
807 " wr_total_time_ns=%" PRId64
808 " rd_total_time_ns=%" PRId64
809 " flush_total_time_ns=%" PRId64
810 " rd_merged=%" PRId64
811 " wr_merged=%" PRId64
812 " idle_time_ns=%" PRId64
814 stats
->value
->stats
->rd_bytes
,
815 stats
->value
->stats
->wr_bytes
,
816 stats
->value
->stats
->rd_operations
,
817 stats
->value
->stats
->wr_operations
,
818 stats
->value
->stats
->flush_operations
,
819 stats
->value
->stats
->wr_total_time_ns
,
820 stats
->value
->stats
->rd_total_time_ns
,
821 stats
->value
->stats
->flush_total_time_ns
,
822 stats
->value
->stats
->rd_merged
,
823 stats
->value
->stats
->wr_merged
,
824 stats
->value
->stats
->idle_time_ns
);
827 qapi_free_BlockStatsList(stats_list
);
830 void hmp_info_block_jobs(Monitor
*mon
, const QDict
*qdict
)
832 BlockJobInfoList
*list
;
834 list
= qmp_query_block_jobs(&error_abort
);
837 monitor_printf(mon
, "No active jobs\n");
842 if (strcmp(list
->value
->type
, "stream") == 0) {
843 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
844 " of %" PRId64
" bytes, speed limit %" PRId64
851 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
852 " of %" PRId64
" bytes, speed limit %" PRId64
863 qapi_free_BlockJobInfoList(list
);
866 void hmp_info_snapshots(Monitor
*mon
, const QDict
*qdict
)
868 BlockDriverState
*bs
, *bs1
;
869 BdrvNextIterator it1
;
870 QEMUSnapshotInfo
*sn_tab
, *sn
;
871 bool no_snapshot
= true;
874 int *global_snapshots
;
875 AioContext
*aio_context
;
877 typedef struct SnapshotEntry
{
879 QTAILQ_ENTRY(SnapshotEntry
) next
;
882 typedef struct ImageEntry
{
883 const char *imagename
;
884 QTAILQ_ENTRY(ImageEntry
) next
;
885 QTAILQ_HEAD(, SnapshotEntry
) snapshots
;
888 QTAILQ_HEAD(, ImageEntry
) image_list
=
889 QTAILQ_HEAD_INITIALIZER(image_list
);
891 ImageEntry
*image_entry
, *next_ie
;
892 SnapshotEntry
*snapshot_entry
;
895 bs
= bdrv_all_find_vmstate_bs(NULL
, false, NULL
, &err
);
897 error_report_err(err
);
900 aio_context
= bdrv_get_aio_context(bs
);
902 aio_context_acquire(aio_context
);
903 nb_sns
= bdrv_snapshot_list(bs
, &sn_tab
);
904 aio_context_release(aio_context
);
907 monitor_printf(mon
, "bdrv_snapshot_list: error %d\n", nb_sns
);
911 for (bs1
= bdrv_first(&it1
); bs1
; bs1
= bdrv_next(&it1
)) {
915 AioContext
*ctx
= bdrv_get_aio_context(bs1
);
917 aio_context_acquire(ctx
);
918 if (bdrv_can_snapshot(bs1
)) {
920 bs1_nb_sns
= bdrv_snapshot_list(bs1
, &sn
);
921 if (bs1_nb_sns
> 0) {
923 ie
= g_new0(ImageEntry
, 1);
924 ie
->imagename
= bdrv_get_device_name(bs1
);
925 QTAILQ_INIT(&ie
->snapshots
);
926 QTAILQ_INSERT_TAIL(&image_list
, ie
, next
);
927 for (i
= 0; i
< bs1_nb_sns
; i
++) {
928 se
= g_new0(SnapshotEntry
, 1);
930 QTAILQ_INSERT_TAIL(&ie
->snapshots
, se
, next
);
935 aio_context_release(ctx
);
939 monitor_printf(mon
, "There is no snapshot available.\n");
943 global_snapshots
= g_new0(int, nb_sns
);
945 for (i
= 0; i
< nb_sns
; i
++) {
946 SnapshotEntry
*next_sn
;
947 if (bdrv_all_has_snapshot(sn_tab
[i
].name
, false, NULL
, NULL
) == 1) {
948 global_snapshots
[total
] = i
;
950 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
951 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
,
953 if (!strcmp(sn_tab
[i
].name
, snapshot_entry
->sn
.name
)) {
954 QTAILQ_REMOVE(&image_entry
->snapshots
, snapshot_entry
,
956 g_free(snapshot_entry
);
962 monitor_printf(mon
, "List of snapshots present on all disks:\n");
965 bdrv_snapshot_dump(NULL
);
966 monitor_printf(mon
, "\n");
967 for (i
= 0; i
< total
; i
++) {
968 sn
= &sn_tab
[global_snapshots
[i
]];
970 * The ID is not guaranteed to be the same on all images, so
973 pstrcpy(sn
->id_str
, sizeof(sn
->id_str
), "--");
974 bdrv_snapshot_dump(sn
);
975 monitor_printf(mon
, "\n");
978 monitor_printf(mon
, "None\n");
981 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
982 if (QTAILQ_EMPTY(&image_entry
->snapshots
)) {
986 "\nList of partial (non-loadable) snapshots on '%s':\n",
987 image_entry
->imagename
);
988 bdrv_snapshot_dump(NULL
);
989 monitor_printf(mon
, "\n");
990 QTAILQ_FOREACH(snapshot_entry
, &image_entry
->snapshots
, next
) {
991 bdrv_snapshot_dump(&snapshot_entry
->sn
);
992 monitor_printf(mon
, "\n");
996 QTAILQ_FOREACH_SAFE(image_entry
, &image_list
, next
, next_ie
) {
997 SnapshotEntry
*next_sn
;
998 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
, next
,
1000 g_free(snapshot_entry
);
1002 g_free(image_entry
);
1005 g_free(global_snapshots
);