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
= qemu_opts_parse_noisily(qemu_find_opts("drive"), optstr
, false);
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 .format
= (char *)format
,
245 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
247 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
252 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
255 qmp_drive_mirror(&mirror
, &err
);
257 hmp_handle_error(mon
, err
);
260 void hmp_drive_backup(Monitor
*mon
, const QDict
*qdict
)
262 const char *device
= qdict_get_str(qdict
, "device");
263 const char *filename
= qdict_get_str(qdict
, "target");
264 const char *format
= qdict_get_try_str(qdict
, "format");
265 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
266 bool full
= qdict_get_try_bool(qdict
, "full", false);
267 bool compress
= qdict_get_try_bool(qdict
, "compress", false);
269 DriveBackup backup
= {
270 .device
= (char *)device
,
271 .target
= (char *)filename
,
272 .format
= (char *)format
,
273 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
275 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
276 .has_compress
= !!compress
,
277 .compress
= compress
,
281 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
285 qmp_drive_backup(&backup
, &err
);
287 hmp_handle_error(mon
, err
);
290 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
293 const char *device
= qdict_get_str(qdict
, "device");
294 int64_t value
= qdict_get_int(qdict
, "speed");
296 qmp_block_job_set_speed(device
, value
, &error
);
298 hmp_handle_error(mon
, error
);
301 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
304 const char *device
= qdict_get_str(qdict
, "device");
305 bool force
= qdict_get_try_bool(qdict
, "force", false);
307 qmp_block_job_cancel(device
, true, force
, &error
);
309 hmp_handle_error(mon
, error
);
312 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
315 const char *device
= qdict_get_str(qdict
, "device");
317 qmp_block_job_pause(device
, &error
);
319 hmp_handle_error(mon
, error
);
322 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
325 const char *device
= qdict_get_str(qdict
, "device");
327 qmp_block_job_resume(device
, &error
);
329 hmp_handle_error(mon
, error
);
332 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
335 const char *device
= qdict_get_str(qdict
, "device");
337 qmp_block_job_complete(device
, &error
);
339 hmp_handle_error(mon
, error
);
342 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
344 const char *device
= qdict_get_str(qdict
, "device");
345 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
346 const char *format
= qdict_get_try_str(qdict
, "format");
347 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
348 enum NewImageMode mode
;
353 * In the future, if 'snapshot-file' is not specified, the snapshot
354 * will be taken internally. Today it's actually required.
356 error_setg(&err
, QERR_MISSING_PARAMETER
, "snapshot-file");
360 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
361 qmp_blockdev_snapshot_sync(device
, NULL
, filename
, NULL
, format
,
364 hmp_handle_error(mon
, err
);
367 void hmp_snapshot_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
369 const char *device
= qdict_get_str(qdict
, "device");
370 const char *name
= qdict_get_str(qdict
, "name");
373 qmp_blockdev_snapshot_internal_sync(device
, name
, &err
);
374 hmp_handle_error(mon
, err
);
377 void hmp_snapshot_delete_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
379 const char *device
= qdict_get_str(qdict
, "device");
380 const char *name
= qdict_get_str(qdict
, "name");
381 const char *id
= qdict_get_try_str(qdict
, "id");
384 qmp_blockdev_snapshot_delete_internal_sync(device
, id
, name
, &err
);
385 hmp_handle_error(mon
, err
);
388 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
390 const char *uri
= qdict_get_str(qdict
, "uri");
391 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
392 bool all
= qdict_get_try_bool(qdict
, "all", false);
393 Error
*local_err
= NULL
;
394 BlockInfoList
*block_list
, *info
;
396 NbdServerAddOptions export
;
398 if (writable
&& !all
) {
399 error_setg(&local_err
, "-w only valid together with -a");
403 /* First check if the address is valid and start the server. */
404 addr
= socket_parse(uri
, &local_err
);
405 if (local_err
!= NULL
) {
409 nbd_server_start(addr
, NULL
, NULL
, 0, &local_err
);
410 qapi_free_SocketAddress(addr
);
411 if (local_err
!= NULL
) {
419 /* Then try adding all block devices. If one fails, close all and
422 block_list
= qmp_query_block(NULL
);
424 for (info
= block_list
; info
; info
= info
->next
) {
425 if (!info
->value
->inserted
) {
429 export
= (NbdServerAddOptions
) {
430 .device
= info
->value
->device
,
431 .has_writable
= true,
432 .writable
= writable
,
435 qmp_nbd_server_add(&export
, &local_err
);
437 if (local_err
!= NULL
) {
438 qmp_nbd_server_stop(NULL
);
443 qapi_free_BlockInfoList(block_list
);
446 hmp_handle_error(mon
, local_err
);
449 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
451 const char *device
= qdict_get_str(qdict
, "device");
452 const char *name
= qdict_get_try_str(qdict
, "name");
453 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
454 Error
*local_err
= NULL
;
456 NbdServerAddOptions export
= {
457 .device
= (char *) device
,
458 .name
= (char *) name
,
459 .has_writable
= true,
460 .writable
= writable
,
463 qmp_nbd_server_add(&export
, &local_err
);
464 hmp_handle_error(mon
, local_err
);
467 void hmp_nbd_server_remove(Monitor
*mon
, const QDict
*qdict
)
469 const char *name
= qdict_get_str(qdict
, "name");
470 bool force
= qdict_get_try_bool(qdict
, "force", false);
473 /* Rely on BLOCK_EXPORT_REMOVE_MODE_SAFE being the default */
474 qmp_nbd_server_remove(name
, force
, BLOCK_EXPORT_REMOVE_MODE_HARD
, &err
);
475 hmp_handle_error(mon
, err
);
478 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
482 qmp_nbd_server_stop(&err
);
483 hmp_handle_error(mon
, err
);
486 void coroutine_fn
hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
488 const char *device
= qdict_get_str(qdict
, "device");
489 int64_t size
= qdict_get_int(qdict
, "size");
492 qmp_block_resize(device
, NULL
, size
, &err
);
493 hmp_handle_error(mon
, err
);
496 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
499 const char *device
= qdict_get_str(qdict
, "device");
500 const char *base
= qdict_get_try_str(qdict
, "base");
501 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
503 qmp_block_stream(device
, device
, base
, NULL
, NULL
, NULL
,
504 qdict_haskey(qdict
, "speed"), speed
,
505 true, BLOCKDEV_ON_ERROR_REPORT
, NULL
,
506 false, false, false, false, &error
);
508 hmp_handle_error(mon
, error
);
511 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
514 char *device
= (char *) qdict_get_str(qdict
, "device");
515 BlockIOThrottle throttle
= {
516 .bps
= qdict_get_int(qdict
, "bps"),
517 .bps_rd
= qdict_get_int(qdict
, "bps_rd"),
518 .bps_wr
= qdict_get_int(qdict
, "bps_wr"),
519 .iops
= qdict_get_int(qdict
, "iops"),
520 .iops_rd
= qdict_get_int(qdict
, "iops_rd"),
521 .iops_wr
= qdict_get_int(qdict
, "iops_wr"),
525 * qmp_block_set_io_throttle has separate parameters for the
526 * (deprecated) block device name and the qdev ID but the HMP
527 * version has only one, so we must decide which one to pass.
529 if (blk_by_name(device
)) {
530 throttle
.device
= device
;
532 throttle
.id
= device
;
535 qmp_block_set_io_throttle(&throttle
, &err
);
536 hmp_handle_error(mon
, err
);
539 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
541 bool force
= qdict_get_try_bool(qdict
, "force", false);
542 const char *device
= qdict_get_str(qdict
, "device");
545 qmp_eject(device
, NULL
, true, force
, &err
);
546 hmp_handle_error(mon
, err
);
549 void hmp_qemu_io(Monitor
*mon
, const QDict
*qdict
)
551 BlockBackend
*blk
= NULL
;
552 BlockDriverState
*bs
= NULL
;
553 BlockBackend
*local_blk
= NULL
;
554 AioContext
*ctx
= NULL
;
555 bool qdev
= qdict_get_try_bool(qdict
, "qdev", false);
556 const char *device
= qdict_get_str(qdict
, "device");
557 const char *command
= qdict_get_str(qdict
, "command");
562 blk
= blk_by_qdev_id(device
, &err
);
567 blk
= blk_by_name(device
);
569 bs
= bdrv_lookup_bs(NULL
, device
, &err
);
576 ctx
= blk
? blk_get_aio_context(blk
) : bdrv_get_aio_context(bs
);
577 aio_context_acquire(ctx
);
580 blk
= local_blk
= blk_new(bdrv_get_aio_context(bs
), 0, BLK_PERM_ALL
);
581 ret
= blk_insert_bs(blk
, bs
, &err
);
588 * Notably absent: Proper permission management. This is sad, but it seems
589 * almost impossible to achieve without changing the semantics and thereby
590 * limiting the use cases of the qemu-io HMP command.
592 * In an ideal world we would unconditionally create a new BlockBackend for
593 * qemuio_command(), but we have commands like 'reopen' and want them to
594 * take effect on the exact BlockBackend whose name the user passed instead
595 * of just on a temporary copy of it.
597 * Another problem is that deleting the temporary BlockBackend involves
598 * draining all requests on it first, but some qemu-iotests cases want to
599 * issue multiple aio_read/write requests and expect them to complete in
600 * the background while the monitor has already returned.
602 * This is also what prevents us from saving the original permissions and
603 * restoring them later: We can't revoke permissions until all requests
604 * have completed, and we don't know when that is nor can we really let
605 * anything else run before we have revoken them to avoid race conditions.
607 * What happens now is that command() in qemu-io-cmds.c can extend the
608 * permissions if necessary for the qemu-io command. And they simply stay
609 * extended, possibly resulting in a read-only guest device keeping write
610 * permissions. Ugly, but it appears to be the lesser evil.
612 qemuio_command(blk
, command
);
615 blk_unref(local_blk
);
618 aio_context_release(ctx
);
621 hmp_handle_error(mon
, err
);
624 static void print_block_info(Monitor
*mon
, BlockInfo
*info
,
625 BlockDeviceInfo
*inserted
, bool verbose
)
627 ImageInfo
*image_info
;
629 assert(!info
|| !info
->inserted
|| info
->inserted
== inserted
);
631 if (info
&& *info
->device
) {
632 monitor_puts(mon
, info
->device
);
633 if (inserted
&& inserted
->node_name
) {
634 monitor_printf(mon
, " (%s)", inserted
->node_name
);
637 assert(info
|| inserted
);
639 inserted
&& inserted
->node_name
? inserted
->node_name
640 : info
&& info
->qdev
? info
->qdev
645 monitor_printf(mon
, ": %s (%s%s%s)\n",
648 inserted
->ro
? ", read-only" : "",
649 inserted
->encrypted
? ", encrypted" : "");
651 monitor_printf(mon
, ": [not inserted]\n");
656 monitor_printf(mon
, " Attached to: %s\n", info
->qdev
);
658 if (info
->has_io_status
&& info
->io_status
!= BLOCK_DEVICE_IO_STATUS_OK
) {
659 monitor_printf(mon
, " I/O status: %s\n",
660 BlockDeviceIoStatus_str(info
->io_status
));
663 if (info
->removable
) {
664 monitor_printf(mon
, " Removable device: %slocked, tray %s\n",
665 info
->locked
? "" : "not ",
666 info
->tray_open
? "open" : "closed");
675 monitor_printf(mon
, " Cache mode: %s%s%s\n",
676 inserted
->cache
->writeback
? "writeback" : "writethrough",
677 inserted
->cache
->direct
? ", direct" : "",
678 inserted
->cache
->no_flush
? ", ignore flushes" : "");
680 if (inserted
->backing_file
) {
683 "(chain depth: %" PRId64
")\n",
684 inserted
->backing_file
,
685 inserted
->backing_file_depth
);
688 if (inserted
->detect_zeroes
!= BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF
) {
689 monitor_printf(mon
, " Detect zeroes: %s\n",
690 BlockdevDetectZeroesOptions_str(inserted
->detect_zeroes
));
693 if (inserted
->bps
|| inserted
->bps_rd
|| inserted
->bps_wr
||
694 inserted
->iops
|| inserted
->iops_rd
|| inserted
->iops_wr
)
696 monitor_printf(mon
, " I/O throttling: bps=%" PRId64
697 " bps_rd=%" PRId64
" bps_wr=%" PRId64
699 " bps_rd_max=%" PRId64
700 " bps_wr_max=%" PRId64
701 " iops=%" PRId64
" iops_rd=%" PRId64
704 " iops_rd_max=%" PRId64
705 " iops_wr_max=%" PRId64
706 " iops_size=%" PRId64
712 inserted
->bps_rd_max
,
713 inserted
->bps_wr_max
,
718 inserted
->iops_rd_max
,
719 inserted
->iops_wr_max
,
725 monitor_printf(mon
, "\nImages:\n");
726 image_info
= inserted
->image
;
728 bdrv_image_info_dump(image_info
);
729 if (image_info
->backing_image
) {
730 image_info
= image_info
->backing_image
;
738 void hmp_info_block(Monitor
*mon
, const QDict
*qdict
)
740 BlockInfoList
*block_list
, *info
;
741 BlockDeviceInfoList
*blockdev_list
, *blockdev
;
742 const char *device
= qdict_get_try_str(qdict
, "device");
743 bool verbose
= qdict_get_try_bool(qdict
, "verbose", false);
744 bool nodes
= qdict_get_try_bool(qdict
, "nodes", false);
745 bool printed
= false;
747 /* Print BlockBackend information */
749 block_list
= qmp_query_block(NULL
);
754 for (info
= block_list
; info
; info
= info
->next
) {
755 if (device
&& strcmp(device
, info
->value
->device
)) {
759 if (info
!= block_list
) {
760 monitor_printf(mon
, "\n");
763 print_block_info(mon
, info
->value
, info
->value
->inserted
,
768 qapi_free_BlockInfoList(block_list
);
770 if ((!device
&& !nodes
) || printed
) {
774 /* Print node information */
775 blockdev_list
= qmp_query_named_block_nodes(false, false, NULL
);
776 for (blockdev
= blockdev_list
; blockdev
; blockdev
= blockdev
->next
) {
777 assert(blockdev
->value
->node_name
);
778 if (device
&& strcmp(device
, blockdev
->value
->node_name
)) {
782 if (blockdev
!= blockdev_list
) {
783 monitor_printf(mon
, "\n");
786 print_block_info(mon
, NULL
, blockdev
->value
, verbose
);
788 qapi_free_BlockDeviceInfoList(blockdev_list
);
791 void hmp_info_blockstats(Monitor
*mon
, const QDict
*qdict
)
793 BlockStatsList
*stats_list
, *stats
;
795 stats_list
= qmp_query_blockstats(false, false, NULL
);
797 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
798 if (!stats
->value
->device
) {
802 monitor_printf(mon
, "%s:", stats
->value
->device
);
803 monitor_printf(mon
, " rd_bytes=%" PRId64
805 " rd_operations=%" PRId64
806 " wr_operations=%" PRId64
807 " flush_operations=%" PRId64
808 " wr_total_time_ns=%" PRId64
809 " rd_total_time_ns=%" PRId64
810 " flush_total_time_ns=%" PRId64
811 " rd_merged=%" PRId64
812 " wr_merged=%" PRId64
813 " idle_time_ns=%" PRId64
815 stats
->value
->stats
->rd_bytes
,
816 stats
->value
->stats
->wr_bytes
,
817 stats
->value
->stats
->rd_operations
,
818 stats
->value
->stats
->wr_operations
,
819 stats
->value
->stats
->flush_operations
,
820 stats
->value
->stats
->wr_total_time_ns
,
821 stats
->value
->stats
->rd_total_time_ns
,
822 stats
->value
->stats
->flush_total_time_ns
,
823 stats
->value
->stats
->rd_merged
,
824 stats
->value
->stats
->wr_merged
,
825 stats
->value
->stats
->idle_time_ns
);
828 qapi_free_BlockStatsList(stats_list
);
831 void hmp_info_block_jobs(Monitor
*mon
, const QDict
*qdict
)
833 BlockJobInfoList
*list
;
835 list
= qmp_query_block_jobs(&error_abort
);
838 monitor_printf(mon
, "No active jobs\n");
843 if (strcmp(list
->value
->type
, "stream") == 0) {
844 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
845 " of %" PRId64
" bytes, speed limit %" PRId64
852 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
853 " of %" PRId64
" bytes, speed limit %" PRId64
864 qapi_free_BlockJobInfoList(list
);
867 void hmp_info_snapshots(Monitor
*mon
, const QDict
*qdict
)
869 BlockDriverState
*bs
, *bs1
;
870 BdrvNextIterator it1
;
871 QEMUSnapshotInfo
*sn_tab
, *sn
;
872 bool no_snapshot
= true;
875 int *global_snapshots
;
876 AioContext
*aio_context
;
878 typedef struct SnapshotEntry
{
880 QTAILQ_ENTRY(SnapshotEntry
) next
;
883 typedef struct ImageEntry
{
884 const char *imagename
;
885 QTAILQ_ENTRY(ImageEntry
) next
;
886 QTAILQ_HEAD(, SnapshotEntry
) snapshots
;
889 QTAILQ_HEAD(, ImageEntry
) image_list
=
890 QTAILQ_HEAD_INITIALIZER(image_list
);
892 ImageEntry
*image_entry
, *next_ie
;
893 SnapshotEntry
*snapshot_entry
;
896 bs
= bdrv_all_find_vmstate_bs(NULL
, false, NULL
, &err
);
898 error_report_err(err
);
901 aio_context
= bdrv_get_aio_context(bs
);
903 aio_context_acquire(aio_context
);
904 nb_sns
= bdrv_snapshot_list(bs
, &sn_tab
);
905 aio_context_release(aio_context
);
908 monitor_printf(mon
, "bdrv_snapshot_list: error %d\n", nb_sns
);
912 for (bs1
= bdrv_first(&it1
); bs1
; bs1
= bdrv_next(&it1
)) {
916 AioContext
*ctx
= bdrv_get_aio_context(bs1
);
918 aio_context_acquire(ctx
);
919 if (bdrv_can_snapshot(bs1
)) {
921 bs1_nb_sns
= bdrv_snapshot_list(bs1
, &sn
);
922 if (bs1_nb_sns
> 0) {
924 ie
= g_new0(ImageEntry
, 1);
925 ie
->imagename
= bdrv_get_device_name(bs1
);
926 QTAILQ_INIT(&ie
->snapshots
);
927 QTAILQ_INSERT_TAIL(&image_list
, ie
, next
);
928 for (i
= 0; i
< bs1_nb_sns
; i
++) {
929 se
= g_new0(SnapshotEntry
, 1);
931 QTAILQ_INSERT_TAIL(&ie
->snapshots
, se
, next
);
936 aio_context_release(ctx
);
940 monitor_printf(mon
, "There is no snapshot available.\n");
944 global_snapshots
= g_new0(int, nb_sns
);
946 for (i
= 0; i
< nb_sns
; i
++) {
947 SnapshotEntry
*next_sn
;
948 if (bdrv_all_has_snapshot(sn_tab
[i
].name
, false, NULL
, NULL
) == 1) {
949 global_snapshots
[total
] = i
;
951 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
952 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
,
954 if (!strcmp(sn_tab
[i
].name
, snapshot_entry
->sn
.name
)) {
955 QTAILQ_REMOVE(&image_entry
->snapshots
, snapshot_entry
,
957 g_free(snapshot_entry
);
963 monitor_printf(mon
, "List of snapshots present on all disks:\n");
966 bdrv_snapshot_dump(NULL
);
967 monitor_printf(mon
, "\n");
968 for (i
= 0; i
< total
; i
++) {
969 sn
= &sn_tab
[global_snapshots
[i
]];
971 * The ID is not guaranteed to be the same on all images, so
974 pstrcpy(sn
->id_str
, sizeof(sn
->id_str
), "--");
975 bdrv_snapshot_dump(sn
);
976 monitor_printf(mon
, "\n");
979 monitor_printf(mon
, "None\n");
982 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
983 if (QTAILQ_EMPTY(&image_entry
->snapshots
)) {
987 "\nList of partial (non-loadable) snapshots on '%s':\n",
988 image_entry
->imagename
);
989 bdrv_snapshot_dump(NULL
);
990 monitor_printf(mon
, "\n");
991 QTAILQ_FOREACH(snapshot_entry
, &image_entry
->snapshots
, next
) {
992 bdrv_snapshot_dump(&snapshot_entry
->sn
);
993 monitor_printf(mon
, "\n");
997 QTAILQ_FOREACH_SAFE(image_entry
, &image_list
, next
, next_ie
) {
998 SnapshotEntry
*next_sn
;
999 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
, next
,
1001 g_free(snapshot_entry
);
1003 g_free(image_entry
);
1006 g_free(global_snapshots
);