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
);
218 bs
= bdrv_skip_implicit_filters(blk_bs(blk
));
219 aio_context
= bdrv_get_aio_context(bs
);
220 aio_context_acquire(aio_context
);
222 if (!blk_is_available(blk
)) {
223 error_report("Device '%s' has no medium", device
);
224 aio_context_release(aio_context
);
228 ret
= bdrv_commit(bs
);
230 aio_context_release(aio_context
);
233 error_report("'commit' error for '%s': %s", device
, strerror(-ret
));
237 void hmp_drive_mirror(Monitor
*mon
, const QDict
*qdict
)
239 const char *filename
= qdict_get_str(qdict
, "target");
240 const char *format
= qdict_get_try_str(qdict
, "format");
241 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
242 bool full
= qdict_get_try_bool(qdict
, "full", false);
244 DriveMirror mirror
= {
245 .device
= (char *)qdict_get_str(qdict
, "device"),
246 .target
= (char *)filename
,
247 .format
= (char *)format
,
248 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
250 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
255 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
258 qmp_drive_mirror(&mirror
, &err
);
260 hmp_handle_error(mon
, err
);
263 void hmp_drive_backup(Monitor
*mon
, const QDict
*qdict
)
265 const char *device
= qdict_get_str(qdict
, "device");
266 const char *filename
= qdict_get_str(qdict
, "target");
267 const char *format
= qdict_get_try_str(qdict
, "format");
268 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
269 bool full
= qdict_get_try_bool(qdict
, "full", false);
270 bool compress
= qdict_get_try_bool(qdict
, "compress", false);
272 DriveBackup backup
= {
273 .device
= (char *)device
,
274 .target
= (char *)filename
,
275 .format
= (char *)format
,
276 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
278 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
279 .has_compress
= !!compress
,
280 .compress
= compress
,
284 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
288 qmp_drive_backup(&backup
, &err
);
290 hmp_handle_error(mon
, err
);
293 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
296 const char *device
= qdict_get_str(qdict
, "device");
297 int64_t value
= qdict_get_int(qdict
, "speed");
299 qmp_block_job_set_speed(device
, value
, &error
);
301 hmp_handle_error(mon
, error
);
304 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
307 const char *device
= qdict_get_str(qdict
, "device");
308 bool force
= qdict_get_try_bool(qdict
, "force", false);
310 qmp_block_job_cancel(device
, true, force
, &error
);
312 hmp_handle_error(mon
, error
);
315 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
318 const char *device
= qdict_get_str(qdict
, "device");
320 qmp_block_job_pause(device
, &error
);
322 hmp_handle_error(mon
, error
);
325 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
328 const char *device
= qdict_get_str(qdict
, "device");
330 qmp_block_job_resume(device
, &error
);
332 hmp_handle_error(mon
, error
);
335 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
338 const char *device
= qdict_get_str(qdict
, "device");
340 qmp_block_job_complete(device
, &error
);
342 hmp_handle_error(mon
, error
);
345 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
347 const char *device
= qdict_get_str(qdict
, "device");
348 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
349 const char *format
= qdict_get_try_str(qdict
, "format");
350 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
351 enum NewImageMode mode
;
356 * In the future, if 'snapshot-file' is not specified, the snapshot
357 * will be taken internally. Today it's actually required.
359 error_setg(&err
, QERR_MISSING_PARAMETER
, "snapshot-file");
363 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
364 qmp_blockdev_snapshot_sync(device
, NULL
, filename
, NULL
, format
,
367 hmp_handle_error(mon
, err
);
370 void hmp_snapshot_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
372 const char *device
= qdict_get_str(qdict
, "device");
373 const char *name
= qdict_get_str(qdict
, "name");
376 qmp_blockdev_snapshot_internal_sync(device
, name
, &err
);
377 hmp_handle_error(mon
, err
);
380 void hmp_snapshot_delete_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
382 const char *device
= qdict_get_str(qdict
, "device");
383 const char *name
= qdict_get_str(qdict
, "name");
384 const char *id
= qdict_get_try_str(qdict
, "id");
387 qmp_blockdev_snapshot_delete_internal_sync(device
, id
, name
, &err
);
388 hmp_handle_error(mon
, err
);
391 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
393 const char *uri
= qdict_get_str(qdict
, "uri");
394 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
395 bool all
= qdict_get_try_bool(qdict
, "all", false);
396 Error
*local_err
= NULL
;
397 BlockInfoList
*block_list
, *info
;
399 NbdServerAddOptions export
;
401 if (writable
&& !all
) {
402 error_setg(&local_err
, "-w only valid together with -a");
406 /* First check if the address is valid and start the server. */
407 addr
= socket_parse(uri
, &local_err
);
408 if (local_err
!= NULL
) {
412 nbd_server_start(addr
, NULL
, NULL
, 0, &local_err
);
413 qapi_free_SocketAddress(addr
);
414 if (local_err
!= NULL
) {
422 /* Then try adding all block devices. If one fails, close all and
425 block_list
= qmp_query_block(NULL
);
427 for (info
= block_list
; info
; info
= info
->next
) {
428 if (!info
->value
->inserted
) {
432 export
= (NbdServerAddOptions
) {
433 .device
= info
->value
->device
,
434 .has_writable
= true,
435 .writable
= writable
,
438 qmp_nbd_server_add(&export
, &local_err
);
440 if (local_err
!= NULL
) {
441 qmp_nbd_server_stop(NULL
);
446 qapi_free_BlockInfoList(block_list
);
449 hmp_handle_error(mon
, local_err
);
452 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
454 const char *device
= qdict_get_str(qdict
, "device");
455 const char *name
= qdict_get_try_str(qdict
, "name");
456 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
457 Error
*local_err
= NULL
;
459 NbdServerAddOptions export
= {
460 .device
= (char *) device
,
461 .name
= (char *) name
,
462 .has_writable
= true,
463 .writable
= writable
,
466 qmp_nbd_server_add(&export
, &local_err
);
467 hmp_handle_error(mon
, local_err
);
470 void hmp_nbd_server_remove(Monitor
*mon
, const QDict
*qdict
)
472 const char *name
= qdict_get_str(qdict
, "name");
473 bool force
= qdict_get_try_bool(qdict
, "force", false);
476 /* Rely on BLOCK_EXPORT_REMOVE_MODE_SAFE being the default */
477 qmp_nbd_server_remove(name
, force
, BLOCK_EXPORT_REMOVE_MODE_HARD
, &err
);
478 hmp_handle_error(mon
, err
);
481 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
485 qmp_nbd_server_stop(&err
);
486 hmp_handle_error(mon
, err
);
489 void coroutine_fn
hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
491 const char *device
= qdict_get_str(qdict
, "device");
492 int64_t size
= qdict_get_int(qdict
, "size");
495 qmp_block_resize(device
, NULL
, size
, &err
);
496 hmp_handle_error(mon
, err
);
499 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
502 const char *device
= qdict_get_str(qdict
, "device");
503 const char *base
= qdict_get_try_str(qdict
, "base");
504 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
506 qmp_block_stream(device
, device
, base
, NULL
, NULL
, NULL
,
507 qdict_haskey(qdict
, "speed"), speed
,
508 true, BLOCKDEV_ON_ERROR_REPORT
, NULL
,
509 false, false, false, false, &error
);
511 hmp_handle_error(mon
, error
);
514 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
517 char *device
= (char *) qdict_get_str(qdict
, "device");
518 BlockIOThrottle throttle
= {
519 .bps
= qdict_get_int(qdict
, "bps"),
520 .bps_rd
= qdict_get_int(qdict
, "bps_rd"),
521 .bps_wr
= qdict_get_int(qdict
, "bps_wr"),
522 .iops
= qdict_get_int(qdict
, "iops"),
523 .iops_rd
= qdict_get_int(qdict
, "iops_rd"),
524 .iops_wr
= qdict_get_int(qdict
, "iops_wr"),
528 * qmp_block_set_io_throttle has separate parameters for the
529 * (deprecated) block device name and the qdev ID but the HMP
530 * version has only one, so we must decide which one to pass.
532 if (blk_by_name(device
)) {
533 throttle
.device
= device
;
535 throttle
.id
= device
;
538 qmp_block_set_io_throttle(&throttle
, &err
);
539 hmp_handle_error(mon
, err
);
542 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
544 bool force
= qdict_get_try_bool(qdict
, "force", false);
545 const char *device
= qdict_get_str(qdict
, "device");
548 qmp_eject(device
, NULL
, true, force
, &err
);
549 hmp_handle_error(mon
, err
);
552 void hmp_qemu_io(Monitor
*mon
, const QDict
*qdict
)
554 BlockBackend
*blk
= NULL
;
555 BlockDriverState
*bs
= NULL
;
556 BlockBackend
*local_blk
= NULL
;
557 AioContext
*ctx
= NULL
;
558 bool qdev
= qdict_get_try_bool(qdict
, "qdev", false);
559 const char *device
= qdict_get_str(qdict
, "device");
560 const char *command
= qdict_get_str(qdict
, "command");
565 blk
= blk_by_qdev_id(device
, &err
);
570 blk
= blk_by_name(device
);
572 bs
= bdrv_lookup_bs(NULL
, device
, &err
);
579 ctx
= blk
? blk_get_aio_context(blk
) : bdrv_get_aio_context(bs
);
580 aio_context_acquire(ctx
);
583 blk
= local_blk
= blk_new(bdrv_get_aio_context(bs
), 0, BLK_PERM_ALL
);
584 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
);
621 aio_context_release(ctx
);
624 hmp_handle_error(mon
, err
);
627 static void print_block_info(Monitor
*mon
, BlockInfo
*info
,
628 BlockDeviceInfo
*inserted
, bool verbose
)
630 ImageInfo
*image_info
;
632 assert(!info
|| !info
->inserted
|| info
->inserted
== inserted
);
634 if (info
&& *info
->device
) {
635 monitor_puts(mon
, info
->device
);
636 if (inserted
&& inserted
->node_name
) {
637 monitor_printf(mon
, " (%s)", inserted
->node_name
);
640 assert(info
|| inserted
);
642 inserted
&& inserted
->node_name
? inserted
->node_name
643 : info
&& info
->qdev
? info
->qdev
648 monitor_printf(mon
, ": %s (%s%s%s)\n",
651 inserted
->ro
? ", read-only" : "",
652 inserted
->encrypted
? ", encrypted" : "");
654 monitor_printf(mon
, ": [not inserted]\n");
659 monitor_printf(mon
, " Attached to: %s\n", info
->qdev
);
661 if (info
->has_io_status
&& info
->io_status
!= BLOCK_DEVICE_IO_STATUS_OK
) {
662 monitor_printf(mon
, " I/O status: %s\n",
663 BlockDeviceIoStatus_str(info
->io_status
));
666 if (info
->removable
) {
667 monitor_printf(mon
, " Removable device: %slocked, tray %s\n",
668 info
->locked
? "" : "not ",
669 info
->tray_open
? "open" : "closed");
678 monitor_printf(mon
, " Cache mode: %s%s%s\n",
679 inserted
->cache
->writeback
? "writeback" : "writethrough",
680 inserted
->cache
->direct
? ", direct" : "",
681 inserted
->cache
->no_flush
? ", ignore flushes" : "");
683 if (inserted
->backing_file
) {
686 "(chain depth: %" PRId64
")\n",
687 inserted
->backing_file
,
688 inserted
->backing_file_depth
);
691 if (inserted
->detect_zeroes
!= BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF
) {
692 monitor_printf(mon
, " Detect zeroes: %s\n",
693 BlockdevDetectZeroesOptions_str(inserted
->detect_zeroes
));
696 if (inserted
->bps
|| inserted
->bps_rd
|| inserted
->bps_wr
||
697 inserted
->iops
|| inserted
->iops_rd
|| inserted
->iops_wr
)
699 monitor_printf(mon
, " I/O throttling: bps=%" PRId64
700 " bps_rd=%" PRId64
" bps_wr=%" PRId64
702 " bps_rd_max=%" PRId64
703 " bps_wr_max=%" PRId64
704 " iops=%" PRId64
" iops_rd=%" PRId64
707 " iops_rd_max=%" PRId64
708 " iops_wr_max=%" PRId64
709 " iops_size=%" PRId64
715 inserted
->bps_rd_max
,
716 inserted
->bps_wr_max
,
721 inserted
->iops_rd_max
,
722 inserted
->iops_wr_max
,
728 monitor_printf(mon
, "\nImages:\n");
729 image_info
= inserted
->image
;
731 bdrv_node_info_dump(qapi_ImageInfo_base(image_info
), 0, false);
732 if (image_info
->backing_image
) {
733 image_info
= image_info
->backing_image
;
741 void hmp_info_block(Monitor
*mon
, const QDict
*qdict
)
743 BlockInfoList
*block_list
, *info
;
744 BlockDeviceInfoList
*blockdev_list
, *blockdev
;
745 const char *device
= qdict_get_try_str(qdict
, "device");
746 bool verbose
= qdict_get_try_bool(qdict
, "verbose", false);
747 bool nodes
= qdict_get_try_bool(qdict
, "nodes", false);
748 bool printed
= false;
750 /* Print BlockBackend information */
752 block_list
= qmp_query_block(NULL
);
757 for (info
= block_list
; info
; info
= info
->next
) {
758 if (device
&& strcmp(device
, info
->value
->device
)) {
762 if (info
!= block_list
) {
763 monitor_printf(mon
, "\n");
766 print_block_info(mon
, info
->value
, info
->value
->inserted
,
771 qapi_free_BlockInfoList(block_list
);
773 if ((!device
&& !nodes
) || printed
) {
777 /* Print node information */
778 blockdev_list
= qmp_query_named_block_nodes(false, false, NULL
);
779 for (blockdev
= blockdev_list
; blockdev
; blockdev
= blockdev
->next
) {
780 assert(blockdev
->value
->node_name
);
781 if (device
&& strcmp(device
, blockdev
->value
->node_name
)) {
785 if (blockdev
!= blockdev_list
) {
786 monitor_printf(mon
, "\n");
789 print_block_info(mon
, NULL
, blockdev
->value
, verbose
);
791 qapi_free_BlockDeviceInfoList(blockdev_list
);
794 void hmp_info_blockstats(Monitor
*mon
, const QDict
*qdict
)
796 BlockStatsList
*stats_list
, *stats
;
798 stats_list
= qmp_query_blockstats(false, false, NULL
);
800 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
801 if (!stats
->value
->device
) {
805 monitor_printf(mon
, "%s:", stats
->value
->device
);
806 monitor_printf(mon
, " rd_bytes=%" PRId64
808 " rd_operations=%" PRId64
809 " wr_operations=%" PRId64
810 " flush_operations=%" PRId64
811 " wr_total_time_ns=%" PRId64
812 " rd_total_time_ns=%" PRId64
813 " flush_total_time_ns=%" PRId64
814 " rd_merged=%" PRId64
815 " wr_merged=%" PRId64
816 " idle_time_ns=%" PRId64
818 stats
->value
->stats
->rd_bytes
,
819 stats
->value
->stats
->wr_bytes
,
820 stats
->value
->stats
->rd_operations
,
821 stats
->value
->stats
->wr_operations
,
822 stats
->value
->stats
->flush_operations
,
823 stats
->value
->stats
->wr_total_time_ns
,
824 stats
->value
->stats
->rd_total_time_ns
,
825 stats
->value
->stats
->flush_total_time_ns
,
826 stats
->value
->stats
->rd_merged
,
827 stats
->value
->stats
->wr_merged
,
828 stats
->value
->stats
->idle_time_ns
);
831 qapi_free_BlockStatsList(stats_list
);
834 void hmp_info_block_jobs(Monitor
*mon
, const QDict
*qdict
)
836 BlockJobInfoList
*list
;
838 list
= qmp_query_block_jobs(&error_abort
);
841 monitor_printf(mon
, "No active jobs\n");
846 if (strcmp(list
->value
->type
, "stream") == 0) {
847 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
848 " of %" PRId64
" bytes, speed limit %" PRId64
855 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
856 " of %" PRId64
" bytes, speed limit %" PRId64
867 qapi_free_BlockJobInfoList(list
);
870 void hmp_info_snapshots(Monitor
*mon
, const QDict
*qdict
)
872 BlockDriverState
*bs
, *bs1
;
873 BdrvNextIterator it1
;
874 QEMUSnapshotInfo
*sn_tab
, *sn
;
875 bool no_snapshot
= true;
878 int *global_snapshots
;
879 AioContext
*aio_context
;
881 typedef struct SnapshotEntry
{
883 QTAILQ_ENTRY(SnapshotEntry
) next
;
886 typedef struct ImageEntry
{
887 const char *imagename
;
888 QTAILQ_ENTRY(ImageEntry
) next
;
889 QTAILQ_HEAD(, SnapshotEntry
) snapshots
;
892 QTAILQ_HEAD(, ImageEntry
) image_list
=
893 QTAILQ_HEAD_INITIALIZER(image_list
);
895 ImageEntry
*image_entry
, *next_ie
;
896 SnapshotEntry
*snapshot_entry
;
899 bs
= bdrv_all_find_vmstate_bs(NULL
, false, NULL
, &err
);
901 error_report_err(err
);
904 aio_context
= bdrv_get_aio_context(bs
);
906 aio_context_acquire(aio_context
);
907 nb_sns
= bdrv_snapshot_list(bs
, &sn_tab
);
908 aio_context_release(aio_context
);
911 monitor_printf(mon
, "bdrv_snapshot_list: error %d\n", nb_sns
);
915 for (bs1
= bdrv_first(&it1
); bs1
; bs1
= bdrv_next(&it1
)) {
919 AioContext
*ctx
= bdrv_get_aio_context(bs1
);
921 aio_context_acquire(ctx
);
922 if (bdrv_can_snapshot(bs1
)) {
924 bs1_nb_sns
= bdrv_snapshot_list(bs1
, &sn
);
925 if (bs1_nb_sns
> 0) {
927 ie
= g_new0(ImageEntry
, 1);
928 ie
->imagename
= bdrv_get_device_name(bs1
);
929 QTAILQ_INIT(&ie
->snapshots
);
930 QTAILQ_INSERT_TAIL(&image_list
, ie
, next
);
931 for (i
= 0; i
< bs1_nb_sns
; i
++) {
932 se
= g_new0(SnapshotEntry
, 1);
934 QTAILQ_INSERT_TAIL(&ie
->snapshots
, se
, next
);
939 aio_context_release(ctx
);
943 monitor_printf(mon
, "There is no snapshot available.\n");
947 global_snapshots
= g_new0(int, nb_sns
);
949 for (i
= 0; i
< nb_sns
; i
++) {
950 SnapshotEntry
*next_sn
;
951 if (bdrv_all_has_snapshot(sn_tab
[i
].name
, false, NULL
, NULL
) == 1) {
952 global_snapshots
[total
] = i
;
954 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
955 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
,
957 if (!strcmp(sn_tab
[i
].name
, snapshot_entry
->sn
.name
)) {
958 QTAILQ_REMOVE(&image_entry
->snapshots
, snapshot_entry
,
960 g_free(snapshot_entry
);
966 monitor_printf(mon
, "List of snapshots present on all disks:\n");
969 bdrv_snapshot_dump(NULL
);
970 monitor_printf(mon
, "\n");
971 for (i
= 0; i
< total
; i
++) {
972 sn
= &sn_tab
[global_snapshots
[i
]];
974 * The ID is not guaranteed to be the same on all images, so
977 pstrcpy(sn
->id_str
, sizeof(sn
->id_str
), "--");
978 bdrv_snapshot_dump(sn
);
979 monitor_printf(mon
, "\n");
982 monitor_printf(mon
, "None\n");
985 QTAILQ_FOREACH(image_entry
, &image_list
, next
) {
986 if (QTAILQ_EMPTY(&image_entry
->snapshots
)) {
990 "\nList of partial (non-loadable) snapshots on '%s':\n",
991 image_entry
->imagename
);
992 bdrv_snapshot_dump(NULL
);
993 monitor_printf(mon
, "\n");
994 QTAILQ_FOREACH(snapshot_entry
, &image_entry
->snapshots
, next
) {
995 bdrv_snapshot_dump(&snapshot_entry
->sn
);
996 monitor_printf(mon
, "\n");
1000 QTAILQ_FOREACH_SAFE(image_entry
, &image_list
, next
, next_ie
) {
1001 SnapshotEntry
*next_sn
;
1002 QTAILQ_FOREACH_SAFE(snapshot_entry
, &image_entry
->snapshots
, next
,
1004 g_free(snapshot_entry
);
1006 g_free(image_entry
);
1009 g_free(global_snapshots
);
1012 void hmp_change_medium(Monitor
*mon
, const char *device
, const char *target
,
1013 const char *arg
, const char *read_only
, bool force
,
1017 BlockdevChangeReadOnlyMode read_only_mode
= 0;
1021 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup
,
1023 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN
, errp
);
1029 qmp_blockdev_change_medium(device
, NULL
, target
, arg
, true, force
,
1030 !!read_only
, read_only_mode
, errp
);