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 "qemu/error-report.h"
52 #include "sysemu/sysemu.h"
53 #include "monitor/monitor.h"
54 #include "monitor/hmp.h"
55 #include "block/nbd.h"
56 #include "block/qapi.h"
57 #include "block/block_int.h"
58 #include "block/block-hmp-cmds.h"
61 static void hmp_drive_add_node(Monitor
*mon
, const char *optstr
)
65 Error
*local_err
= NULL
;
67 opts
= qemu_opts_parse_noisily(&qemu_drive_opts
, optstr
, false);
72 qdict
= qemu_opts_to_qdict(opts
, NULL
);
74 if (!qdict_get_try_str(qdict
, "node-name")) {
76 error_report("'node-name' needs to be specified");
80 BlockDriverState
*bs
= bds_tree_init(qdict
, &local_err
);
82 error_report_err(local_err
);
86 bdrv_set_monitor_owned(bs
);
91 void hmp_drive_add(Monitor
*mon
, const QDict
*qdict
)
97 const char *optstr
= qdict_get_str(qdict
, "opts");
98 bool node
= qdict_get_try_bool(qdict
, "node", false);
101 hmp_drive_add_node(mon
, optstr
);
105 opts
= qemu_opts_parse_noisily(qemu_find_opts("drive"), optstr
, false);
109 mc
= MACHINE_GET_CLASS(current_machine
);
110 dinfo
= drive_new(opts
, mc
->block_default_type
, &err
);
112 error_report_err(err
);
121 switch (dinfo
->type
) {
123 monitor_printf(mon
, "OK\n");
126 monitor_printf(mon
, "Can't hot-add drive to type %d\n", dinfo
->type
);
133 BlockBackend
*blk
= blk_by_legacy_dinfo(dinfo
);
134 monitor_remove_blk(blk
);
139 void hmp_drive_del(Monitor
*mon
, const QDict
*qdict
)
141 const char *id
= qdict_get_str(qdict
, "id");
143 BlockDriverState
*bs
;
144 AioContext
*aio_context
;
145 Error
*local_err
= NULL
;
147 bs
= bdrv_find_node(id
);
149 qmp_blockdev_del(id
, &local_err
);
151 error_report_err(local_err
);
156 blk
= blk_by_name(id
);
158 error_report("Device '%s' not found", id
);
162 if (!blk_legacy_dinfo(blk
)) {
163 error_report("Deleting device added with blockdev-add"
164 " is not supported");
168 aio_context
= blk_get_aio_context(blk
);
169 aio_context_acquire(aio_context
);
173 if (bdrv_op_is_blocked(bs
, BLOCK_OP_TYPE_DRIVE_DEL
, &local_err
)) {
174 error_report_err(local_err
);
175 aio_context_release(aio_context
);
182 /* Make the BlockBackend and the attached BlockDriverState anonymous */
183 monitor_remove_blk(blk
);
186 * If this BlockBackend has a device attached to it, its refcount will be
187 * decremented when the device is removed; otherwise we have to do so here.
189 if (blk_get_attached_dev(blk
)) {
190 /* Further I/O must not pause the guest */
191 blk_set_on_error(blk
, BLOCKDEV_ON_ERROR_REPORT
,
192 BLOCKDEV_ON_ERROR_REPORT
);
197 aio_context_release(aio_context
);
200 void hmp_commit(Monitor
*mon
, const QDict
*qdict
)
202 const char *device
= qdict_get_str(qdict
, "device");
206 if (!strcmp(device
, "all")) {
207 ret
= blk_commit_all();
209 BlockDriverState
*bs
;
210 AioContext
*aio_context
;
212 blk
= blk_by_name(device
);
214 error_report("Device '%s' not found", device
);
217 if (!blk_is_available(blk
)) {
218 error_report("Device '%s' has no medium", device
);
222 bs
= bdrv_skip_implicit_filters(blk_bs(blk
));
223 aio_context
= bdrv_get_aio_context(bs
);
224 aio_context_acquire(aio_context
);
226 ret
= bdrv_commit(bs
);
228 aio_context_release(aio_context
);
231 error_report("'commit' error for '%s': %s", device
, strerror(-ret
));
235 void hmp_drive_mirror(Monitor
*mon
, const QDict
*qdict
)
237 const char *filename
= qdict_get_str(qdict
, "target");
238 const char *format
= qdict_get_try_str(qdict
, "format");
239 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
240 bool full
= qdict_get_try_bool(qdict
, "full", false);
242 DriveMirror mirror
= {
243 .device
= (char *)qdict_get_str(qdict
, "device"),
244 .target
= (char *)filename
,
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");
256 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 .format
= (char *)format
,
274 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
276 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
277 .has_compress
= !!compress
,
278 .compress
= compress
,
282 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
286 qmp_drive_backup(&backup
, &err
);
288 hmp_handle_error(mon
, err
);
291 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
294 const char *device
= qdict_get_str(qdict
, "device");
295 int64_t value
= qdict_get_int(qdict
, "speed");
297 qmp_block_job_set_speed(device
, value
, &error
);
299 hmp_handle_error(mon
, error
);
302 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
305 const char *device
= qdict_get_str(qdict
, "device");
306 bool force
= qdict_get_try_bool(qdict
, "force", false);
308 qmp_block_job_cancel(device
, true, force
, &error
);
310 hmp_handle_error(mon
, error
);
313 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
316 const char *device
= qdict_get_str(qdict
, "device");
318 qmp_block_job_pause(device
, &error
);
320 hmp_handle_error(mon
, error
);
323 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
326 const char *device
= qdict_get_str(qdict
, "device");
328 qmp_block_job_resume(device
, &error
);
330 hmp_handle_error(mon
, error
);
333 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
336 const char *device
= qdict_get_str(qdict
, "device");
338 qmp_block_job_complete(device
, &error
);
340 hmp_handle_error(mon
, error
);
343 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
345 const char *device
= qdict_get_str(qdict
, "device");
346 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
347 const char *format
= qdict_get_try_str(qdict
, "format");
348 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
349 enum NewImageMode mode
;
354 * In the future, if 'snapshot-file' is not specified, the snapshot
355 * will be taken internally. Today it's actually required.
357 error_setg(&err
, QERR_MISSING_PARAMETER
, "snapshot-file");
361 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
362 qmp_blockdev_snapshot_sync(device
, NULL
, filename
, NULL
, format
,
365 hmp_handle_error(mon
, err
);
368 void hmp_snapshot_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
370 const char *device
= qdict_get_str(qdict
, "device");
371 const char *name
= qdict_get_str(qdict
, "name");
374 qmp_blockdev_snapshot_internal_sync(device
, name
, &err
);
375 hmp_handle_error(mon
, err
);
378 void hmp_snapshot_delete_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
380 const char *device
= qdict_get_str(qdict
, "device");
381 const char *name
= qdict_get_str(qdict
, "name");
382 const char *id
= qdict_get_try_str(qdict
, "id");
385 qmp_blockdev_snapshot_delete_internal_sync(device
, id
, name
, &err
);
386 hmp_handle_error(mon
, err
);
389 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
391 const char *uri
= qdict_get_str(qdict
, "uri");
392 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
393 bool all
= qdict_get_try_bool(qdict
, "all", false);
394 Error
*local_err
= NULL
;
395 BlockInfoList
*block_list
, *info
;
397 NbdServerAddOptions export
;
399 if (writable
&& !all
) {
400 error_setg(&local_err
, "-w only valid together with -a");
404 /* First check if the address is valid and start the server. */
405 addr
= socket_parse(uri
, &local_err
);
406 if (local_err
!= NULL
) {
410 nbd_server_start(addr
, NULL
, NULL
, 0, &local_err
);
411 qapi_free_SocketAddress(addr
);
412 if (local_err
!= NULL
) {
420 /* Then try adding all block devices. If one fails, close all and
423 block_list
= qmp_query_block(NULL
);
425 for (info
= block_list
; info
; info
= info
->next
) {
426 if (!info
->value
->inserted
) {
430 export
= (NbdServerAddOptions
) {
431 .device
= info
->value
->device
,
432 .has_writable
= true,
433 .writable
= writable
,
436 qmp_nbd_server_add(&export
, &local_err
);
438 if (local_err
!= NULL
) {
439 qmp_nbd_server_stop(NULL
);
444 qapi_free_BlockInfoList(block_list
);
447 hmp_handle_error(mon
, local_err
);
450 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
452 const char *device
= qdict_get_str(qdict
, "device");
453 const char *name
= qdict_get_try_str(qdict
, "name");
454 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
455 Error
*local_err
= NULL
;
457 NbdServerAddOptions export
= {
458 .device
= (char *) device
,
459 .name
= (char *) name
,
460 .has_writable
= true,
461 .writable
= writable
,
464 qmp_nbd_server_add(&export
, &local_err
);
465 hmp_handle_error(mon
, local_err
);
468 void hmp_nbd_server_remove(Monitor
*mon
, const QDict
*qdict
)
470 const char *name
= qdict_get_str(qdict
, "name");
471 bool force
= qdict_get_try_bool(qdict
, "force", false);
474 /* Rely on BLOCK_EXPORT_REMOVE_MODE_SAFE being the default */
475 qmp_nbd_server_remove(name
, force
, BLOCK_EXPORT_REMOVE_MODE_HARD
, &err
);
476 hmp_handle_error(mon
, err
);
479 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
483 qmp_nbd_server_stop(&err
);
484 hmp_handle_error(mon
, err
);
487 void coroutine_fn
hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
489 const char *device
= qdict_get_str(qdict
, "device");
490 int64_t size
= qdict_get_int(qdict
, "size");
493 qmp_block_resize(device
, NULL
, size
, &err
);
494 hmp_handle_error(mon
, err
);
497 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
500 const char *device
= qdict_get_str(qdict
, "device");
501 const char *base
= qdict_get_try_str(qdict
, "base");
502 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
504 qmp_block_stream(device
, device
, base
, NULL
, NULL
, NULL
,
505 qdict_haskey(qdict
, "speed"), speed
,
506 true, BLOCKDEV_ON_ERROR_REPORT
, NULL
,
507 false, false, false, false, &error
);
509 hmp_handle_error(mon
, error
);
512 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
515 char *device
= (char *) qdict_get_str(qdict
, "device");
516 BlockIOThrottle throttle
= {
517 .bps
= qdict_get_int(qdict
, "bps"),
518 .bps_rd
= qdict_get_int(qdict
, "bps_rd"),
519 .bps_wr
= qdict_get_int(qdict
, "bps_wr"),
520 .iops
= qdict_get_int(qdict
, "iops"),
521 .iops_rd
= qdict_get_int(qdict
, "iops_rd"),
522 .iops_wr
= qdict_get_int(qdict
, "iops_wr"),
526 * qmp_block_set_io_throttle has separate parameters for the
527 * (deprecated) block device name and the qdev ID but the HMP
528 * version has only one, so we must decide which one to pass.
530 if (blk_by_name(device
)) {
531 throttle
.device
= device
;
533 throttle
.id
= device
;
536 qmp_block_set_io_throttle(&throttle
, &err
);
537 hmp_handle_error(mon
, err
);
540 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
542 bool force
= qdict_get_try_bool(qdict
, "force", false);
543 const char *device
= qdict_get_str(qdict
, "device");
546 qmp_eject(device
, NULL
, true, force
, &err
);
547 hmp_handle_error(mon
, err
);
550 void hmp_qemu_io(Monitor
*mon
, const QDict
*qdict
)
552 BlockBackend
*blk
= NULL
;
553 BlockDriverState
*bs
= NULL
;
554 BlockBackend
*local_blk
= NULL
;
555 AioContext
*ctx
= NULL
;
556 bool qdev
= qdict_get_try_bool(qdict
, "qdev", false);
557 const char *device
= qdict_get_str(qdict
, "device");
558 const char *command
= qdict_get_str(qdict
, "command");
563 blk
= blk_by_qdev_id(device
, &err
);
568 blk
= blk_by_name(device
);
570 bs
= bdrv_lookup_bs(NULL
, device
, &err
);
577 ctx
= blk
? blk_get_aio_context(blk
) : bdrv_get_aio_context(bs
);
578 aio_context_acquire(ctx
);
581 blk
= local_blk
= blk_new(bdrv_get_aio_context(bs
), 0, BLK_PERM_ALL
);
582 ret
= blk_insert_bs(blk
, bs
, &err
);
589 * Notably absent: Proper permission management. This is sad, but it seems
590 * almost impossible to achieve without changing the semantics and thereby
591 * limiting the use cases of the qemu-io HMP command.
593 * In an ideal world we would unconditionally create a new BlockBackend for
594 * qemuio_command(), but we have commands like 'reopen' and want them to
595 * take effect on the exact BlockBackend whose name the user passed instead
596 * of just on a temporary copy of it.
598 * Another problem is that deleting the temporary BlockBackend involves
599 * draining all requests on it first, but some qemu-iotests cases want to
600 * issue multiple aio_read/write requests and expect them to complete in
601 * the background while the monitor has already returned.
603 * This is also what prevents us from saving the original permissions and
604 * restoring them later: We can't revoke permissions until all requests
605 * have completed, and we don't know when that is nor can we really let
606 * anything else run before we have revoken them to avoid race conditions.
608 * What happens now is that command() in qemu-io-cmds.c can extend the
609 * permissions if necessary for the qemu-io command. And they simply stay
610 * extended, possibly resulting in a read-only guest device keeping write
611 * permissions. Ugly, but it appears to be the lesser evil.
613 qemuio_command(blk
, command
);
616 blk_unref(local_blk
);
619 aio_context_release(ctx
);
622 hmp_handle_error(mon
, err
);
625 static void print_block_info(Monitor
*mon
, BlockInfo
*info
,
626 BlockDeviceInfo
*inserted
, bool verbose
)
628 ImageInfo
*image_info
;
630 assert(!info
|| !info
->inserted
|| info
->inserted
== inserted
);
632 if (info
&& *info
->device
) {
633 monitor_puts(mon
, info
->device
);
634 if (inserted
&& inserted
->node_name
) {
635 monitor_printf(mon
, " (%s)", inserted
->node_name
);
638 assert(info
|| inserted
);
640 inserted
&& inserted
->node_name
? inserted
->node_name
641 : info
&& info
->qdev
? info
->qdev
646 monitor_printf(mon
, ": %s (%s%s%s)\n",
649 inserted
->ro
? ", read-only" : "",
650 inserted
->encrypted
? ", encrypted" : "");
652 monitor_printf(mon
, ": [not inserted]\n");
657 monitor_printf(mon
, " Attached to: %s\n", info
->qdev
);
659 if (info
->has_io_status
&& info
->io_status
!= BLOCK_DEVICE_IO_STATUS_OK
) {
660 monitor_printf(mon
, " I/O status: %s\n",
661 BlockDeviceIoStatus_str(info
->io_status
));
664 if (info
->removable
) {
665 monitor_printf(mon
, " Removable device: %slocked, tray %s\n",
666 info
->locked
? "" : "not ",
667 info
->tray_open
? "open" : "closed");
676 monitor_printf(mon
, " Cache mode: %s%s%s\n",
677 inserted
->cache
->writeback
? "writeback" : "writethrough",
678 inserted
->cache
->direct
? ", direct" : "",
679 inserted
->cache
->no_flush
? ", ignore flushes" : "");
681 if (inserted
->backing_file
) {
684 "(chain depth: %" PRId64
")\n",
685 inserted
->backing_file
,
686 inserted
->backing_file_depth
);
689 if (inserted
->detect_zeroes
!= BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF
) {
690 monitor_printf(mon
, " Detect zeroes: %s\n",
691 BlockdevDetectZeroesOptions_str(inserted
->detect_zeroes
));
694 if (inserted
->bps
|| inserted
->bps_rd
|| inserted
->bps_wr
||
695 inserted
->iops
|| inserted
->iops_rd
|| inserted
->iops_wr
)
697 monitor_printf(mon
, " I/O throttling: bps=%" PRId64
698 " bps_rd=%" PRId64
" bps_wr=%" PRId64
700 " bps_rd_max=%" PRId64
701 " bps_wr_max=%" PRId64
702 " iops=%" PRId64
" iops_rd=%" PRId64
705 " iops_rd_max=%" PRId64
706 " iops_wr_max=%" PRId64
707 " iops_size=%" PRId64
713 inserted
->bps_rd_max
,
714 inserted
->bps_wr_max
,
719 inserted
->iops_rd_max
,
720 inserted
->iops_wr_max
,
726 monitor_printf(mon
, "\nImages:\n");
727 image_info
= inserted
->image
;
729 bdrv_node_info_dump(qapi_ImageInfo_base(image_info
), 0, false);
730 if (image_info
->backing_image
) {
731 image_info
= image_info
->backing_image
;
739 void hmp_info_block(Monitor
*mon
, const QDict
*qdict
)
741 BlockInfoList
*block_list
, *info
;
742 BlockDeviceInfoList
*blockdev_list
, *blockdev
;
743 const char *device
= qdict_get_try_str(qdict
, "device");
744 bool verbose
= qdict_get_try_bool(qdict
, "verbose", false);
745 bool nodes
= qdict_get_try_bool(qdict
, "nodes", false);
746 bool printed
= false;
748 /* Print BlockBackend information */
750 block_list
= qmp_query_block(NULL
);
755 for (info
= block_list
; info
; info
= info
->next
) {
756 if (device
&& strcmp(device
, info
->value
->device
)) {
760 if (info
!= block_list
) {
761 monitor_printf(mon
, "\n");
764 print_block_info(mon
, info
->value
, info
->value
->inserted
,
769 qapi_free_BlockInfoList(block_list
);
771 if ((!device
&& !nodes
) || printed
) {
775 /* Print node information */
776 blockdev_list
= qmp_query_named_block_nodes(false, false, NULL
);
777 for (blockdev
= blockdev_list
; blockdev
; blockdev
= blockdev
->next
) {
778 assert(blockdev
->value
->node_name
);
779 if (device
&& strcmp(device
, blockdev
->value
->node_name
)) {
783 if (blockdev
!= blockdev_list
) {
784 monitor_printf(mon
, "\n");
787 print_block_info(mon
, NULL
, blockdev
->value
, verbose
);
789 qapi_free_BlockDeviceInfoList(blockdev_list
);
792 void hmp_info_blockstats(Monitor
*mon
, const QDict
*qdict
)
794 BlockStatsList
*stats_list
, *stats
;
796 stats_list
= qmp_query_blockstats(false, false, NULL
);
798 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
799 if (!stats
->value
->device
) {
803 monitor_printf(mon
, "%s:", stats
->value
->device
);
804 monitor_printf(mon
, " rd_bytes=%" PRId64
806 " rd_operations=%" PRId64
807 " wr_operations=%" PRId64
808 " flush_operations=%" PRId64
809 " wr_total_time_ns=%" PRId64
810 " rd_total_time_ns=%" PRId64
811 " flush_total_time_ns=%" PRId64
812 " rd_merged=%" PRId64
813 " wr_merged=%" PRId64
814 " idle_time_ns=%" PRId64
816 stats
->value
->stats
->rd_bytes
,
817 stats
->value
->stats
->wr_bytes
,
818 stats
->value
->stats
->rd_operations
,
819 stats
->value
->stats
->wr_operations
,
820 stats
->value
->stats
->flush_operations
,
821 stats
->value
->stats
->wr_total_time_ns
,
822 stats
->value
->stats
->rd_total_time_ns
,
823 stats
->value
->stats
->flush_total_time_ns
,
824 stats
->value
->stats
->rd_merged
,
825 stats
->value
->stats
->wr_merged
,
826 stats
->value
->stats
->idle_time_ns
);
829 qapi_free_BlockStatsList(stats_list
);
832 void hmp_info_block_jobs(Monitor
*mon
, const QDict
*qdict
)
834 BlockJobInfoList
*list
;
836 list
= qmp_query_block_jobs(&error_abort
);
839 monitor_printf(mon
, "No active jobs\n");
844 if (strcmp(list
->value
->type
, "stream") == 0) {
845 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
846 " of %" PRId64
" bytes, speed limit %" PRId64
853 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
854 " of %" PRId64
" bytes, speed limit %" PRId64
865 qapi_free_BlockJobInfoList(list
);
868 void hmp_info_snapshots(Monitor
*mon
, const QDict
*qdict
)
870 BlockDriverState
*bs
, *bs1
;
871 BdrvNextIterator it1
;
872 QEMUSnapshotInfo
*sn_tab
, *sn
;
873 bool no_snapshot
= true;
876 int *global_snapshots
;
877 AioContext
*aio_context
;
879 typedef struct SnapshotEntry
{
881 QTAILQ_ENTRY(SnapshotEntry
) next
;
884 typedef struct ImageEntry
{
885 const char *imagename
;
886 QTAILQ_ENTRY(ImageEntry
) next
;
887 QTAILQ_HEAD(, SnapshotEntry
) snapshots
;
890 QTAILQ_HEAD(, ImageEntry
) image_list
=
891 QTAILQ_HEAD_INITIALIZER(image_list
);
893 ImageEntry
*image_entry
, *next_ie
;
894 SnapshotEntry
*snapshot_entry
;
897 bs
= bdrv_all_find_vmstate_bs(NULL
, false, NULL
, &err
);
899 error_report_err(err
);
902 aio_context
= bdrv_get_aio_context(bs
);
904 aio_context_acquire(aio_context
);
905 nb_sns
= bdrv_snapshot_list(bs
, &sn_tab
);
906 aio_context_release(aio_context
);
909 monitor_printf(mon
, "bdrv_snapshot_list: error %d\n", nb_sns
);
913 for (bs1
= bdrv_first(&it1
); bs1
; bs1
= bdrv_next(&it1
)) {
917 AioContext
*ctx
= bdrv_get_aio_context(bs1
);
919 aio_context_acquire(ctx
);
920 if (bdrv_can_snapshot(bs1
)) {
922 bs1_nb_sns
= bdrv_snapshot_list(bs1
, &sn
);
923 if (bs1_nb_sns
> 0) {
925 ie
= g_new0(ImageEntry
, 1);
926 ie
->imagename
= bdrv_get_device_name(bs1
);
927 QTAILQ_INIT(&ie
->snapshots
);
928 QTAILQ_INSERT_TAIL(&image_list
, ie
, next
);
929 for (i
= 0; i
< bs1_nb_sns
; i
++) {
930 se
= g_new0(SnapshotEntry
, 1);
932 QTAILQ_INSERT_TAIL(&ie
->snapshots
, se
, next
);
937 aio_context_release(ctx
);
941 monitor_printf(mon
, "There is no snapshot available.\n");
945 global_snapshots
= g_new0(int, nb_sns
);
947 for (i
= 0; i
< nb_sns
; i
++) {
948 SnapshotEntry
*next_sn
;
949 if (bdrv_all_has_snapshot(sn_tab
[i
].name
, false, NULL
, NULL
) == 1) {
950 global_snapshots
[total
] = i
;
952 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
953 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
,
955 if (!strcmp(sn_tab
[i
].name
, snapshot_entry
->sn
.name
)) {
956 QTAILQ_REMOVE(&image_entry
->snapshots
, snapshot_entry
,
958 g_free(snapshot_entry
);
964 monitor_printf(mon
, "List of snapshots present on all disks:\n");
967 bdrv_snapshot_dump(NULL
);
968 monitor_printf(mon
, "\n");
969 for (i
= 0; i
< total
; i
++) {
970 sn
= &sn_tab
[global_snapshots
[i
]];
972 * The ID is not guaranteed to be the same on all images, so
975 pstrcpy(sn
->id_str
, sizeof(sn
->id_str
), "--");
976 bdrv_snapshot_dump(sn
);
977 monitor_printf(mon
, "\n");
980 monitor_printf(mon
, "None\n");
983 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
984 if (QTAILQ_EMPTY(&image_entry
->snapshots
)) {
988 "\nList of partial (non-loadable) snapshots on '%s':\n",
989 image_entry
->imagename
);
990 bdrv_snapshot_dump(NULL
);
991 monitor_printf(mon
, "\n");
992 QTAILQ_FOREACH(snapshot_entry
, &image_entry
->snapshots
, next
) {
993 bdrv_snapshot_dump(&snapshot_entry
->sn
);
994 monitor_printf(mon
, "\n");
998 QTAILQ_FOREACH_SAFE(image_entry
, &image_list
, next
, next_ie
) {
999 SnapshotEntry
*next_sn
;
1000 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
, next
,
1002 g_free(snapshot_entry
);
1004 g_free(image_entry
);
1007 g_free(global_snapshots
);
1010 void hmp_change_medium(Monitor
*mon
, const char *device
, const char *target
,
1011 const char *arg
, const char *read_only
, bool force
,
1015 BlockdevChangeReadOnlyMode read_only_mode
= 0;
1019 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup
,
1021 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN
, errp
);
1027 qmp_blockdev_change_medium(device
, NULL
, target
, arg
, true, force
,
1028 !!read_only
, read_only_mode
, errp
);