2 * QEMU host block devices
4 * Copyright (c) 2003-2008 Fabrice Bellard
6 * This work is licensed under the terms of the GNU GPL, version 2 or
7 * later. See the COPYING file in the top-level directory.
9 * This file incorporates work covered by the following copyright and
12 * Copyright (c) 2003-2008 Fabrice Bellard
14 * Permission is hereby granted, free of charge, to any person obtaining a copy
15 * of this software and associated documentation files (the "Software"), to deal
16 * in the Software without restriction, including without limitation the rights
17 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18 * copies of the Software, and to permit persons to whom the Software is
19 * furnished to do so, subject to the following conditions:
21 * The above copyright notice and this permission notice shall be included in
22 * all copies or substantial portions of the Software.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
33 #include "sysemu/blockdev.h"
34 #include "hw/block/block.h"
35 #include "block/blockjob.h"
36 #include "monitor/monitor.h"
37 #include "qemu/option.h"
38 #include "qemu/config-file.h"
39 #include "qapi/qmp/types.h"
40 #include "qapi-visit.h"
41 #include "qapi/qmp-output-visitor.h"
42 #include "sysemu/sysemu.h"
43 #include "block/block_int.h"
44 #include "qmp-commands.h"
46 #include "sysemu/arch_init.h"
48 static QTAILQ_HEAD(drivelist
, DriveInfo
) drives
= QTAILQ_HEAD_INITIALIZER(drives
);
50 static const char *const if_name
[IF_COUNT
] = {
54 [IF_FLOPPY
] = "floppy",
55 [IF_PFLASH
] = "pflash",
58 [IF_VIRTIO
] = "virtio",
62 static const int if_max_devs
[IF_COUNT
] = {
64 * Do not change these numbers! They govern how drive option
65 * index maps to unit and bus. That mapping is ABI.
67 * All controllers used to imlement if=T drives need to support
68 * if_max_devs[T] units, for any T with if_max_devs[T] != 0.
69 * Otherwise, some index values map to "impossible" bus, unit
72 * For instance, if you change [IF_SCSI] to 255, -drive
73 * if=scsi,index=12 no longer means bus=1,unit=5, but
74 * bus=0,unit=12. With an lsi53c895a controller (7 units max),
75 * the drive can't be set up. Regression.
82 * We automatically delete the drive when a device using it gets
83 * unplugged. Questionable feature, but we can't just drop it.
84 * Device models call blockdev_mark_auto_del() to schedule the
85 * automatic deletion, and generic qdev code calls blockdev_auto_del()
86 * when deletion is actually safe.
88 void blockdev_mark_auto_del(BlockDriverState
*bs
)
90 DriveInfo
*dinfo
= drive_get_by_blockdev(bs
);
92 if (dinfo
&& !dinfo
->enable_auto_del
) {
97 block_job_cancel(bs
->job
);
104 void blockdev_auto_del(BlockDriverState
*bs
)
106 DriveInfo
*dinfo
= drive_get_by_blockdev(bs
);
108 if (dinfo
&& dinfo
->auto_del
) {
113 static int drive_index_to_bus_id(BlockInterfaceType type
, int index
)
115 int max_devs
= if_max_devs
[type
];
116 return max_devs
? index
/ max_devs
: 0;
119 static int drive_index_to_unit_id(BlockInterfaceType type
, int index
)
121 int max_devs
= if_max_devs
[type
];
122 return max_devs
? index
% max_devs
: index
;
125 QemuOpts
*drive_def(const char *optstr
)
127 return qemu_opts_parse(qemu_find_opts("drive"), optstr
, 0);
130 QemuOpts
*drive_add(BlockInterfaceType type
, int index
, const char *file
,
136 opts
= drive_def(optstr
);
140 if (type
!= IF_DEFAULT
) {
141 qemu_opt_set(opts
, "if", if_name
[type
]);
144 snprintf(buf
, sizeof(buf
), "%d", index
);
145 qemu_opt_set(opts
, "index", buf
);
148 qemu_opt_set(opts
, "file", file
);
152 DriveInfo
*drive_get(BlockInterfaceType type
, int bus
, int unit
)
156 /* seek interface, bus and unit */
158 QTAILQ_FOREACH(dinfo
, &drives
, next
) {
159 if (dinfo
->type
== type
&&
168 DriveInfo
*drive_get_by_index(BlockInterfaceType type
, int index
)
170 return drive_get(type
,
171 drive_index_to_bus_id(type
, index
),
172 drive_index_to_unit_id(type
, index
));
175 int drive_get_max_bus(BlockInterfaceType type
)
181 QTAILQ_FOREACH(dinfo
, &drives
, next
) {
182 if(dinfo
->type
== type
&&
183 dinfo
->bus
> max_bus
)
184 max_bus
= dinfo
->bus
;
189 /* Get a block device. This should only be used for single-drive devices
190 (e.g. SD/Floppy/MTD). Multi-disk devices (scsi/ide) should use the
192 DriveInfo
*drive_get_next(BlockInterfaceType type
)
194 static int next_block_unit
[IF_COUNT
];
196 return drive_get(type
, 0, next_block_unit
[type
]++);
199 DriveInfo
*drive_get_by_blockdev(BlockDriverState
*bs
)
203 QTAILQ_FOREACH(dinfo
, &drives
, next
) {
204 if (dinfo
->bdrv
== bs
) {
211 static void bdrv_format_print(void *opaque
, const char *name
)
213 error_printf(" %s", name
);
216 void drive_del(DriveInfo
*dinfo
)
219 qemu_opts_del(dinfo
->opts
);
222 bdrv_unref(dinfo
->bdrv
);
224 QTAILQ_REMOVE(&drives
, dinfo
, next
);
225 g_free(dinfo
->serial
);
231 BlockDriverState
*bs
;
234 static void bdrv_put_ref_bh(void *opaque
)
236 BDRVPutRefBH
*s
= opaque
;
239 qemu_bh_delete(s
->bh
);
244 * Release a BDS reference in a BH
246 * It is not safe to use bdrv_unref() from a callback function when the callers
247 * still need the BlockDriverState. In such cases we schedule a BH to release
250 static void bdrv_put_ref_bh_schedule(BlockDriverState
*bs
)
254 s
= g_new(BDRVPutRefBH
, 1);
255 s
->bh
= qemu_bh_new(bdrv_put_ref_bh
, s
);
257 qemu_bh_schedule(s
->bh
);
260 static int parse_block_error_action(const char *buf
, bool is_read
, Error
**errp
)
262 if (!strcmp(buf
, "ignore")) {
263 return BLOCKDEV_ON_ERROR_IGNORE
;
264 } else if (!is_read
&& !strcmp(buf
, "enospc")) {
265 return BLOCKDEV_ON_ERROR_ENOSPC
;
266 } else if (!strcmp(buf
, "stop")) {
267 return BLOCKDEV_ON_ERROR_STOP
;
268 } else if (!strcmp(buf
, "report")) {
269 return BLOCKDEV_ON_ERROR_REPORT
;
271 error_setg(errp
, "'%s' invalid %s error action",
272 buf
, is_read
? "read" : "write");
277 static inline int parse_enum_option(const char *lookup
[], const char *buf
,
278 int max
, int def
, Error
**errp
)
286 for (i
= 0; i
< max
; i
++) {
287 if (!strcmp(buf
, lookup
[i
])) {
292 error_setg(errp
, "invalid parameter value: %s", buf
);
296 static bool check_throttle_config(ThrottleConfig
*cfg
, Error
**errp
)
298 if (throttle_conflicting(cfg
)) {
299 error_setg(errp
, "bps/iops/max total values and read/write values"
300 " cannot be used at the same time");
304 if (!throttle_is_valid(cfg
)) {
305 error_setg(errp
, "bps/iops/maxs values must be 0 or greater");
312 typedef enum { MEDIA_DISK
, MEDIA_CDROM
} DriveMediaType
;
314 /* Takes the ownership of bs_opts */
315 static DriveInfo
*blockdev_init(const char *file
, QDict
*bs_opts
,
321 int on_read_error
, on_write_error
;
330 bool has_driver_specific_opts
;
331 BlockdevDetectZeroesOptions detect_zeroes
;
332 BlockDriver
*drv
= NULL
;
334 /* Check common options by copying from bs_opts to opts, all other options
335 * stay in bs_opts for processing by bdrv_open(). */
336 id
= qdict_get_try_str(bs_opts
, "id");
337 opts
= qemu_opts_create(&qemu_common_drive_opts
, id
, 1, &error
);
339 error_propagate(errp
, error
);
343 qemu_opts_absorb_qdict(opts
, bs_opts
, &error
);
345 error_propagate(errp
, error
);
350 qdict_del(bs_opts
, "id");
353 has_driver_specific_opts
= !!qdict_size(bs_opts
);
355 /* extract parameters */
356 snapshot
= qemu_opt_get_bool(opts
, "snapshot", 0);
357 ro
= qemu_opt_get_bool(opts
, "read-only", 0);
358 copy_on_read
= qemu_opt_get_bool(opts
, "copy-on-read", false);
360 if ((buf
= qemu_opt_get(opts
, "discard")) != NULL
) {
361 if (bdrv_parse_discard_flags(buf
, &bdrv_flags
) != 0) {
362 error_setg(errp
, "invalid discard option");
367 if (qemu_opt_get_bool(opts
, "cache.writeback", true)) {
368 bdrv_flags
|= BDRV_O_CACHE_WB
;
370 if (qemu_opt_get_bool(opts
, "cache.direct", false)) {
371 bdrv_flags
|= BDRV_O_NOCACHE
;
373 if (qemu_opt_get_bool(opts
, "cache.no-flush", false)) {
374 bdrv_flags
|= BDRV_O_NO_FLUSH
;
377 #ifdef CONFIG_LINUX_AIO
378 if ((buf
= qemu_opt_get(opts
, "aio")) != NULL
) {
379 if (!strcmp(buf
, "native")) {
380 bdrv_flags
|= BDRV_O_NATIVE_AIO
;
381 } else if (!strcmp(buf
, "threads")) {
382 /* this is the default */
384 error_setg(errp
, "invalid aio option");
390 if ((buf
= qemu_opt_get(opts
, "format")) != NULL
) {
391 if (is_help_option(buf
)) {
392 error_printf("Supported formats:");
393 bdrv_iterate_format(bdrv_format_print
, NULL
);
398 drv
= bdrv_find_format(buf
);
400 error_setg(errp
, "'%s' invalid format", buf
);
405 /* disk I/O throttling */
406 memset(&cfg
, 0, sizeof(cfg
));
407 cfg
.buckets
[THROTTLE_BPS_TOTAL
].avg
=
408 qemu_opt_get_number(opts
, "throttling.bps-total", 0);
409 cfg
.buckets
[THROTTLE_BPS_READ
].avg
=
410 qemu_opt_get_number(opts
, "throttling.bps-read", 0);
411 cfg
.buckets
[THROTTLE_BPS_WRITE
].avg
=
412 qemu_opt_get_number(opts
, "throttling.bps-write", 0);
413 cfg
.buckets
[THROTTLE_OPS_TOTAL
].avg
=
414 qemu_opt_get_number(opts
, "throttling.iops-total", 0);
415 cfg
.buckets
[THROTTLE_OPS_READ
].avg
=
416 qemu_opt_get_number(opts
, "throttling.iops-read", 0);
417 cfg
.buckets
[THROTTLE_OPS_WRITE
].avg
=
418 qemu_opt_get_number(opts
, "throttling.iops-write", 0);
420 cfg
.buckets
[THROTTLE_BPS_TOTAL
].max
=
421 qemu_opt_get_number(opts
, "throttling.bps-total-max", 0);
422 cfg
.buckets
[THROTTLE_BPS_READ
].max
=
423 qemu_opt_get_number(opts
, "throttling.bps-read-max", 0);
424 cfg
.buckets
[THROTTLE_BPS_WRITE
].max
=
425 qemu_opt_get_number(opts
, "throttling.bps-write-max", 0);
426 cfg
.buckets
[THROTTLE_OPS_TOTAL
].max
=
427 qemu_opt_get_number(opts
, "throttling.iops-total-max", 0);
428 cfg
.buckets
[THROTTLE_OPS_READ
].max
=
429 qemu_opt_get_number(opts
, "throttling.iops-read-max", 0);
430 cfg
.buckets
[THROTTLE_OPS_WRITE
].max
=
431 qemu_opt_get_number(opts
, "throttling.iops-write-max", 0);
433 cfg
.op_size
= qemu_opt_get_number(opts
, "throttling.iops-size", 0);
435 if (!check_throttle_config(&cfg
, &error
)) {
436 error_propagate(errp
, error
);
440 on_write_error
= BLOCKDEV_ON_ERROR_ENOSPC
;
441 if ((buf
= qemu_opt_get(opts
, "werror")) != NULL
) {
442 on_write_error
= parse_block_error_action(buf
, 0, &error
);
444 error_propagate(errp
, error
);
449 on_read_error
= BLOCKDEV_ON_ERROR_REPORT
;
450 if ((buf
= qemu_opt_get(opts
, "rerror")) != NULL
) {
451 on_read_error
= parse_block_error_action(buf
, 1, &error
);
453 error_propagate(errp
, error
);
459 parse_enum_option(BlockdevDetectZeroesOptions_lookup
,
460 qemu_opt_get(opts
, "detect-zeroes"),
461 BLOCKDEV_DETECT_ZEROES_OPTIONS_MAX
,
462 BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF
,
465 error_propagate(errp
, error
);
469 if (detect_zeroes
== BLOCKDEV_DETECT_ZEROES_OPTIONS_UNMAP
&&
470 !(bdrv_flags
& BDRV_O_UNMAP
)) {
471 error_setg(errp
, "setting detect-zeroes to unmap is not allowed "
472 "without setting discard operation to unmap");
477 dinfo
= g_malloc0(sizeof(*dinfo
));
478 dinfo
->id
= g_strdup(qemu_opts_id(opts
));
479 dinfo
->bdrv
= bdrv_new(dinfo
->id
, &error
);
481 error_propagate(errp
, error
);
484 dinfo
->bdrv
->open_flags
= snapshot
? BDRV_O_SNAPSHOT
: 0;
485 dinfo
->bdrv
->read_only
= ro
;
486 dinfo
->bdrv
->detect_zeroes
= detect_zeroes
;
487 QTAILQ_INSERT_TAIL(&drives
, dinfo
, next
);
489 bdrv_set_on_error(dinfo
->bdrv
, on_read_error
, on_write_error
);
491 /* disk I/O throttling */
492 if (throttle_enabled(&cfg
)) {
493 bdrv_io_limits_enable(dinfo
->bdrv
);
494 bdrv_set_io_limits(dinfo
->bdrv
, &cfg
);
497 if (!file
|| !*file
) {
498 if (has_driver_specific_opts
) {
507 /* always use cache=unsafe with snapshot */
508 bdrv_flags
&= ~BDRV_O_CACHE_MASK
;
509 bdrv_flags
|= (BDRV_O_SNAPSHOT
|BDRV_O_CACHE_WB
|BDRV_O_NO_FLUSH
);
513 bdrv_flags
|= BDRV_O_COPY_ON_READ
;
516 if (runstate_check(RUN_STATE_INMIGRATE
)) {
517 bdrv_flags
|= BDRV_O_INCOMING
;
520 bdrv_flags
|= ro
? 0 : BDRV_O_RDWR
;
523 ret
= bdrv_open(&dinfo
->bdrv
, file
, NULL
, bs_opts
, bdrv_flags
, drv
, &error
);
526 error_setg(errp
, "could not open disk image %s: %s",
527 file
?: dinfo
->id
, error_get_pretty(error
));
532 if (bdrv_key_required(dinfo
->bdrv
))
541 bdrv_unref(dinfo
->bdrv
);
542 QTAILQ_REMOVE(&drives
, dinfo
, next
);
553 static void qemu_opt_rename(QemuOpts
*opts
, const char *from
, const char *to
)
557 value
= qemu_opt_get(opts
, from
);
559 qemu_opt_set(opts
, to
, value
);
560 qemu_opt_unset(opts
, from
);
564 QemuOptsList qemu_legacy_drive_opts
= {
566 .head
= QTAILQ_HEAD_INITIALIZER(qemu_legacy_drive_opts
.head
),
570 .type
= QEMU_OPT_NUMBER
,
571 .help
= "bus number",
574 .type
= QEMU_OPT_NUMBER
,
575 .help
= "unit number (i.e. lun for scsi)",
578 .type
= QEMU_OPT_NUMBER
,
579 .help
= "index number",
582 .type
= QEMU_OPT_STRING
,
583 .help
= "media type (disk, cdrom)",
586 .type
= QEMU_OPT_STRING
,
587 .help
= "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)",
590 .type
= QEMU_OPT_NUMBER
,
591 .help
= "number of cylinders (ide disk geometry)",
594 .type
= QEMU_OPT_NUMBER
,
595 .help
= "number of heads (ide disk geometry)",
598 .type
= QEMU_OPT_NUMBER
,
599 .help
= "number of sectors (ide disk geometry)",
602 .type
= QEMU_OPT_STRING
,
603 .help
= "chs translation (auto, lba, none)",
606 .type
= QEMU_OPT_BOOL
,
607 .help
= "(deprecated, ignored)",
610 .type
= QEMU_OPT_STRING
,
611 .help
= "pci address (virtio only)",
614 .type
= QEMU_OPT_STRING
,
615 .help
= "disk serial number",
618 .type
= QEMU_OPT_STRING
,
622 /* Options that are passed on, but have special semantics with -drive */
625 .type
= QEMU_OPT_BOOL
,
626 .help
= "open drive file as read-only",
629 .type
= QEMU_OPT_STRING
,
630 .help
= "read error action",
633 .type
= QEMU_OPT_STRING
,
634 .help
= "write error action",
636 .name
= "copy-on-read",
637 .type
= QEMU_OPT_BOOL
,
638 .help
= "copy read data from backing file into image file",
641 { /* end of list */ }
645 DriveInfo
*drive_new(QemuOpts
*all_opts
, BlockInterfaceType block_default_type
)
648 DriveInfo
*dinfo
= NULL
;
650 QemuOpts
*legacy_opts
;
651 DriveMediaType media
= MEDIA_DISK
;
652 BlockInterfaceType type
;
653 int cyls
, heads
, secs
, translation
;
654 int max_devs
, bus_id
, unit_id
, index
;
656 const char *werror
, *rerror
;
657 bool read_only
= false;
660 const char *filename
;
661 Error
*local_err
= NULL
;
663 /* Change legacy command line options into QMP ones */
664 qemu_opt_rename(all_opts
, "iops", "throttling.iops-total");
665 qemu_opt_rename(all_opts
, "iops_rd", "throttling.iops-read");
666 qemu_opt_rename(all_opts
, "iops_wr", "throttling.iops-write");
668 qemu_opt_rename(all_opts
, "bps", "throttling.bps-total");
669 qemu_opt_rename(all_opts
, "bps_rd", "throttling.bps-read");
670 qemu_opt_rename(all_opts
, "bps_wr", "throttling.bps-write");
672 qemu_opt_rename(all_opts
, "iops_max", "throttling.iops-total-max");
673 qemu_opt_rename(all_opts
, "iops_rd_max", "throttling.iops-read-max");
674 qemu_opt_rename(all_opts
, "iops_wr_max", "throttling.iops-write-max");
676 qemu_opt_rename(all_opts
, "bps_max", "throttling.bps-total-max");
677 qemu_opt_rename(all_opts
, "bps_rd_max", "throttling.bps-read-max");
678 qemu_opt_rename(all_opts
, "bps_wr_max", "throttling.bps-write-max");
680 qemu_opt_rename(all_opts
,
681 "iops_size", "throttling.iops-size");
683 qemu_opt_rename(all_opts
, "readonly", "read-only");
685 value
= qemu_opt_get(all_opts
, "cache");
689 if (bdrv_parse_cache_flags(value
, &flags
) != 0) {
690 error_report("invalid cache option");
694 /* Specific options take precedence */
695 if (!qemu_opt_get(all_opts
, "cache.writeback")) {
696 qemu_opt_set_bool(all_opts
, "cache.writeback",
697 !!(flags
& BDRV_O_CACHE_WB
));
699 if (!qemu_opt_get(all_opts
, "cache.direct")) {
700 qemu_opt_set_bool(all_opts
, "cache.direct",
701 !!(flags
& BDRV_O_NOCACHE
));
703 if (!qemu_opt_get(all_opts
, "cache.no-flush")) {
704 qemu_opt_set_bool(all_opts
, "cache.no-flush",
705 !!(flags
& BDRV_O_NO_FLUSH
));
707 qemu_opt_unset(all_opts
, "cache");
710 /* Get a QDict for processing the options */
711 bs_opts
= qdict_new();
712 qemu_opts_to_qdict(all_opts
, bs_opts
);
714 legacy_opts
= qemu_opts_create(&qemu_legacy_drive_opts
, NULL
, 0,
716 qemu_opts_absorb_qdict(legacy_opts
, bs_opts
, &local_err
);
718 error_report("%s", error_get_pretty(local_err
));
719 error_free(local_err
);
723 /* Deprecated option boot=[on|off] */
724 if (qemu_opt_get(legacy_opts
, "boot") != NULL
) {
725 fprintf(stderr
, "qemu-kvm: boot=on|off is deprecated and will be "
726 "ignored. Future versions will reject this parameter. Please "
727 "update your scripts.\n");
731 value
= qemu_opt_get(legacy_opts
, "media");
733 if (!strcmp(value
, "disk")) {
735 } else if (!strcmp(value
, "cdrom")) {
739 error_report("'%s' invalid media", value
);
744 /* copy-on-read is disabled with a warning for read-only devices */
745 read_only
|= qemu_opt_get_bool(legacy_opts
, "read-only", false);
746 copy_on_read
= qemu_opt_get_bool(legacy_opts
, "copy-on-read", false);
748 if (read_only
&& copy_on_read
) {
749 error_report("warning: disabling copy-on-read on read-only drive");
750 copy_on_read
= false;
753 qdict_put(bs_opts
, "read-only",
754 qstring_from_str(read_only
? "on" : "off"));
755 qdict_put(bs_opts
, "copy-on-read",
756 qstring_from_str(copy_on_read
? "on" :"off"));
758 /* Controller type */
759 value
= qemu_opt_get(legacy_opts
, "if");
762 type
< IF_COUNT
&& strcmp(value
, if_name
[type
]);
765 if (type
== IF_COUNT
) {
766 error_report("unsupported bus type '%s'", value
);
770 type
= block_default_type
;
774 cyls
= qemu_opt_get_number(legacy_opts
, "cyls", 0);
775 heads
= qemu_opt_get_number(legacy_opts
, "heads", 0);
776 secs
= qemu_opt_get_number(legacy_opts
, "secs", 0);
778 if (cyls
|| heads
|| secs
) {
780 error_report("invalid physical cyls number");
784 error_report("invalid physical heads number");
788 error_report("invalid physical secs number");
793 translation
= BIOS_ATA_TRANSLATION_AUTO
;
794 value
= qemu_opt_get(legacy_opts
, "trans");
797 error_report("'%s' trans must be used with cyls, heads and secs",
801 if (!strcmp(value
, "none")) {
802 translation
= BIOS_ATA_TRANSLATION_NONE
;
803 } else if (!strcmp(value
, "lba")) {
804 translation
= BIOS_ATA_TRANSLATION_LBA
;
805 } else if (!strcmp(value
, "large")) {
806 translation
= BIOS_ATA_TRANSLATION_LARGE
;
807 } else if (!strcmp(value
, "rechs")) {
808 translation
= BIOS_ATA_TRANSLATION_RECHS
;
809 } else if (!strcmp(value
, "auto")) {
810 translation
= BIOS_ATA_TRANSLATION_AUTO
;
812 error_report("'%s' invalid translation type", value
);
817 if (media
== MEDIA_CDROM
) {
818 if (cyls
|| secs
|| heads
) {
819 error_report("CHS can't be set with media=cdrom");
824 /* Device address specified by bus/unit or index.
825 * If none was specified, try to find the first free one. */
826 bus_id
= qemu_opt_get_number(legacy_opts
, "bus", 0);
827 unit_id
= qemu_opt_get_number(legacy_opts
, "unit", -1);
828 index
= qemu_opt_get_number(legacy_opts
, "index", -1);
830 max_devs
= if_max_devs
[type
];
833 if (bus_id
!= 0 || unit_id
!= -1) {
834 error_report("index cannot be used with bus and unit");
837 bus_id
= drive_index_to_bus_id(type
, index
);
838 unit_id
= drive_index_to_unit_id(type
, index
);
843 while (drive_get(type
, bus_id
, unit_id
) != NULL
) {
845 if (max_devs
&& unit_id
>= max_devs
) {
852 if (max_devs
&& unit_id
>= max_devs
) {
853 error_report("unit %d too big (max is %d)", unit_id
, max_devs
- 1);
857 if (drive_get(type
, bus_id
, unit_id
) != NULL
) {
858 error_report("drive with bus=%d, unit=%d (index=%d) exists",
859 bus_id
, unit_id
, index
);
864 serial
= qemu_opt_get(legacy_opts
, "serial");
866 /* no id supplied -> create one */
867 if (qemu_opts_id(all_opts
) == NULL
) {
869 const char *mediastr
= "";
870 if (type
== IF_IDE
|| type
== IF_SCSI
) {
871 mediastr
= (media
== MEDIA_CDROM
) ? "-cd" : "-hd";
874 new_id
= g_strdup_printf("%s%i%s%i", if_name
[type
], bus_id
,
877 new_id
= g_strdup_printf("%s%s%i", if_name
[type
],
880 qdict_put(bs_opts
, "id", qstring_from_str(new_id
));
884 /* Add virtio block device */
885 devaddr
= qemu_opt_get(legacy_opts
, "addr");
886 if (devaddr
&& type
!= IF_VIRTIO
) {
887 error_report("addr is not supported by this bus type");
891 if (type
== IF_VIRTIO
) {
893 devopts
= qemu_opts_create(qemu_find_opts("device"), NULL
, 0,
895 if (arch_type
== QEMU_ARCH_S390X
) {
896 qemu_opt_set(devopts
, "driver", "virtio-blk-s390");
898 qemu_opt_set(devopts
, "driver", "virtio-blk-pci");
900 qemu_opt_set(devopts
, "drive", qdict_get_str(bs_opts
, "id"));
902 qemu_opt_set(devopts
, "addr", devaddr
);
906 filename
= qemu_opt_get(legacy_opts
, "file");
908 /* Check werror/rerror compatibility with if=... */
909 werror
= qemu_opt_get(legacy_opts
, "werror");
910 if (werror
!= NULL
) {
911 if (type
!= IF_IDE
&& type
!= IF_SCSI
&& type
!= IF_VIRTIO
&&
913 error_report("werror is not supported by this bus type");
916 qdict_put(bs_opts
, "werror", qstring_from_str(werror
));
919 rerror
= qemu_opt_get(legacy_opts
, "rerror");
920 if (rerror
!= NULL
) {
921 if (type
!= IF_IDE
&& type
!= IF_VIRTIO
&& type
!= IF_SCSI
&&
923 error_report("rerror is not supported by this bus type");
926 qdict_put(bs_opts
, "rerror", qstring_from_str(rerror
));
929 /* Actual block device init: Functionality shared with blockdev-add */
930 dinfo
= blockdev_init(filename
, bs_opts
, &local_err
);
934 error_report("%s", error_get_pretty(local_err
));
935 error_free(local_err
);
942 /* Set legacy DriveInfo fields */
943 dinfo
->enable_auto_del
= true;
944 dinfo
->opts
= all_opts
;
947 dinfo
->heads
= heads
;
949 dinfo
->trans
= translation
;
953 dinfo
->unit
= unit_id
;
954 dinfo
->devaddr
= devaddr
;
956 dinfo
->serial
= g_strdup(serial
);
963 dinfo
->media_cd
= media
== MEDIA_CDROM
;
970 qemu_opts_del(legacy_opts
);
975 void do_commit(Monitor
*mon
, const QDict
*qdict
)
977 const char *device
= qdict_get_str(qdict
, "device");
978 BlockDriverState
*bs
;
981 if (!strcmp(device
, "all")) {
982 ret
= bdrv_commit_all();
984 bs
= bdrv_find(device
);
986 monitor_printf(mon
, "Device '%s' not found\n", device
);
989 ret
= bdrv_commit(bs
);
992 monitor_printf(mon
, "'commit' error for '%s': %s\n", device
,
997 static void blockdev_do_action(int kind
, void *data
, Error
**errp
)
999 TransactionAction action
;
1000 TransactionActionList list
;
1004 list
.value
= &action
;
1006 qmp_transaction(&list
, errp
);
1009 void qmp_blockdev_snapshot_sync(bool has_device
, const char *device
,
1010 bool has_node_name
, const char *node_name
,
1011 const char *snapshot_file
,
1012 bool has_snapshot_node_name
,
1013 const char *snapshot_node_name
,
1014 bool has_format
, const char *format
,
1015 bool has_mode
, NewImageMode mode
, Error
**errp
)
1017 BlockdevSnapshot snapshot
= {
1018 .has_device
= has_device
,
1019 .device
= (char *) device
,
1020 .has_node_name
= has_node_name
,
1021 .node_name
= (char *) node_name
,
1022 .snapshot_file
= (char *) snapshot_file
,
1023 .has_snapshot_node_name
= has_snapshot_node_name
,
1024 .snapshot_node_name
= (char *) snapshot_node_name
,
1025 .has_format
= has_format
,
1026 .format
= (char *) format
,
1027 .has_mode
= has_mode
,
1030 blockdev_do_action(TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC
,
1034 void qmp_blockdev_snapshot_internal_sync(const char *device
,
1038 BlockdevSnapshotInternal snapshot
= {
1039 .device
= (char *) device
,
1040 .name
= (char *) name
1043 blockdev_do_action(TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_INTERNAL_SYNC
,
1047 SnapshotInfo
*qmp_blockdev_snapshot_delete_internal_sync(const char *device
,
1054 BlockDriverState
*bs
= bdrv_find(device
);
1055 QEMUSnapshotInfo sn
;
1056 Error
*local_err
= NULL
;
1057 SnapshotInfo
*info
= NULL
;
1061 error_set(errp
, QERR_DEVICE_NOT_FOUND
, device
);
1074 error_setg(errp
, "Name or id must be provided");
1078 ret
= bdrv_snapshot_find_by_id_and_name(bs
, id
, name
, &sn
, &local_err
);
1080 error_propagate(errp
, local_err
);
1085 "Snapshot with id '%s' and name '%s' does not exist on "
1087 STR_OR_NULL(id
), STR_OR_NULL(name
), device
);
1091 bdrv_snapshot_delete(bs
, id
, name
, &local_err
);
1093 error_propagate(errp
, local_err
);
1097 info
= g_malloc0(sizeof(SnapshotInfo
));
1098 info
->id
= g_strdup(sn
.id_str
);
1099 info
->name
= g_strdup(sn
.name
);
1100 info
->date_nsec
= sn
.date_nsec
;
1101 info
->date_sec
= sn
.date_sec
;
1102 info
->vm_state_size
= sn
.vm_state_size
;
1103 info
->vm_clock_nsec
= sn
.vm_clock_nsec
% 1000000000;
1104 info
->vm_clock_sec
= sn
.vm_clock_nsec
/ 1000000000;
1109 /* New and old BlockDriverState structs for group snapshots */
1111 typedef struct BlkTransactionState BlkTransactionState
;
1113 /* Only prepare() may fail. In a single transaction, only one of commit() or
1114 abort() will be called, clean() will always be called if it present. */
1115 typedef struct BdrvActionOps
{
1116 /* Size of state struct, in bytes. */
1117 size_t instance_size
;
1118 /* Prepare the work, must NOT be NULL. */
1119 void (*prepare
)(BlkTransactionState
*common
, Error
**errp
);
1120 /* Commit the changes, can be NULL. */
1121 void (*commit
)(BlkTransactionState
*common
);
1122 /* Abort the changes on fail, can be NULL. */
1123 void (*abort
)(BlkTransactionState
*common
);
1124 /* Clean up resource in the end, can be NULL. */
1125 void (*clean
)(BlkTransactionState
*common
);
1129 * This structure must be arranged as first member in child type, assuming
1130 * that compiler will also arrange it to the same address with parent instance.
1131 * Later it will be used in free().
1133 struct BlkTransactionState
{
1134 TransactionAction
*action
;
1135 const BdrvActionOps
*ops
;
1136 QSIMPLEQ_ENTRY(BlkTransactionState
) entry
;
1139 /* internal snapshot private data */
1140 typedef struct InternalSnapshotState
{
1141 BlkTransactionState common
;
1142 BlockDriverState
*bs
;
1143 QEMUSnapshotInfo sn
;
1144 } InternalSnapshotState
;
1146 static void internal_snapshot_prepare(BlkTransactionState
*common
,
1149 Error
*local_err
= NULL
;
1152 BlockDriverState
*bs
;
1153 QEMUSnapshotInfo old_sn
, *sn
;
1156 BlockdevSnapshotInternal
*internal
;
1157 InternalSnapshotState
*state
;
1160 g_assert(common
->action
->kind
==
1161 TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_INTERNAL_SYNC
);
1162 internal
= common
->action
->blockdev_snapshot_internal_sync
;
1163 state
= DO_UPCAST(InternalSnapshotState
, common
, common
);
1165 /* 1. parse input */
1166 device
= internal
->device
;
1167 name
= internal
->name
;
1169 /* 2. check for validation */
1170 bs
= bdrv_find(device
);
1172 error_set(errp
, QERR_DEVICE_NOT_FOUND
, device
);
1176 if (!bdrv_is_inserted(bs
)) {
1177 error_set(errp
, QERR_DEVICE_HAS_NO_MEDIUM
, device
);
1181 if (bdrv_is_read_only(bs
)) {
1182 error_set(errp
, QERR_DEVICE_IS_READ_ONLY
, device
);
1186 if (!bdrv_can_snapshot(bs
)) {
1187 error_set(errp
, QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED
,
1188 bs
->drv
->format_name
, device
, "internal snapshot");
1192 if (!strlen(name
)) {
1193 error_setg(errp
, "Name is empty");
1197 /* check whether a snapshot with name exist */
1198 ret
= bdrv_snapshot_find_by_id_and_name(bs
, NULL
, name
, &old_sn
,
1201 error_propagate(errp
, local_err
);
1205 "Snapshot with name '%s' already exists on device '%s'",
1210 /* 3. take the snapshot */
1212 pstrcpy(sn
->name
, sizeof(sn
->name
), name
);
1213 qemu_gettimeofday(&tv
);
1214 sn
->date_sec
= tv
.tv_sec
;
1215 sn
->date_nsec
= tv
.tv_usec
* 1000;
1216 sn
->vm_clock_nsec
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
);
1218 ret1
= bdrv_snapshot_create(bs
, sn
);
1220 error_setg_errno(errp
, -ret1
,
1221 "Failed to create snapshot '%s' on device '%s'",
1226 /* 4. succeed, mark a snapshot is created */
1230 static void internal_snapshot_abort(BlkTransactionState
*common
)
1232 InternalSnapshotState
*state
=
1233 DO_UPCAST(InternalSnapshotState
, common
, common
);
1234 BlockDriverState
*bs
= state
->bs
;
1235 QEMUSnapshotInfo
*sn
= &state
->sn
;
1236 Error
*local_error
= NULL
;
1242 if (bdrv_snapshot_delete(bs
, sn
->id_str
, sn
->name
, &local_error
) < 0) {
1243 error_report("Failed to delete snapshot with id '%s' and name '%s' on "
1244 "device '%s' in abort: %s",
1247 bdrv_get_device_name(bs
),
1248 error_get_pretty(local_error
));
1249 error_free(local_error
);
1253 /* external snapshot private data */
1254 typedef struct ExternalSnapshotState
{
1255 BlkTransactionState common
;
1256 BlockDriverState
*old_bs
;
1257 BlockDriverState
*new_bs
;
1258 } ExternalSnapshotState
;
1260 static void external_snapshot_prepare(BlkTransactionState
*common
,
1265 QDict
*options
= NULL
;
1266 Error
*local_err
= NULL
;
1267 bool has_device
= false;
1269 bool has_node_name
= false;
1270 const char *node_name
;
1271 bool has_snapshot_node_name
= false;
1272 const char *snapshot_node_name
;
1273 const char *new_image_file
;
1274 const char *format
= "qcow2";
1275 enum NewImageMode mode
= NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
1276 ExternalSnapshotState
*state
=
1277 DO_UPCAST(ExternalSnapshotState
, common
, common
);
1278 TransactionAction
*action
= common
->action
;
1280 /* get parameters */
1281 g_assert(action
->kind
== TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC
);
1283 has_device
= action
->blockdev_snapshot_sync
->has_device
;
1284 device
= action
->blockdev_snapshot_sync
->device
;
1285 has_node_name
= action
->blockdev_snapshot_sync
->has_node_name
;
1286 node_name
= action
->blockdev_snapshot_sync
->node_name
;
1287 has_snapshot_node_name
=
1288 action
->blockdev_snapshot_sync
->has_snapshot_node_name
;
1289 snapshot_node_name
= action
->blockdev_snapshot_sync
->snapshot_node_name
;
1291 new_image_file
= action
->blockdev_snapshot_sync
->snapshot_file
;
1292 if (action
->blockdev_snapshot_sync
->has_format
) {
1293 format
= action
->blockdev_snapshot_sync
->format
;
1295 if (action
->blockdev_snapshot_sync
->has_mode
) {
1296 mode
= action
->blockdev_snapshot_sync
->mode
;
1299 /* start processing */
1300 drv
= bdrv_find_format(format
);
1302 error_set(errp
, QERR_INVALID_BLOCK_FORMAT
, format
);
1306 state
->old_bs
= bdrv_lookup_bs(has_device
? device
: NULL
,
1307 has_node_name
? node_name
: NULL
,
1310 error_propagate(errp
, local_err
);
1314 if (has_node_name
&& !has_snapshot_node_name
) {
1315 error_setg(errp
, "New snapshot node name missing");
1319 if (has_snapshot_node_name
&& bdrv_find_node(snapshot_node_name
)) {
1320 error_setg(errp
, "New snapshot node name already existing");
1324 if (!bdrv_is_inserted(state
->old_bs
)) {
1325 error_set(errp
, QERR_DEVICE_HAS_NO_MEDIUM
, device
);
1329 if (bdrv_op_is_blocked(state
->old_bs
,
1330 BLOCK_OP_TYPE_EXTERNAL_SNAPSHOT
, errp
)) {
1334 if (!bdrv_is_read_only(state
->old_bs
)) {
1335 if (bdrv_flush(state
->old_bs
)) {
1336 error_set(errp
, QERR_IO_ERROR
);
1341 if (!bdrv_is_first_non_filter(state
->old_bs
)) {
1342 error_set(errp
, QERR_FEATURE_DISABLED
, "snapshot");
1346 flags
= state
->old_bs
->open_flags
;
1348 /* create new image w/backing file */
1349 if (mode
!= NEW_IMAGE_MODE_EXISTING
) {
1350 bdrv_img_create(new_image_file
, format
,
1351 state
->old_bs
->filename
,
1352 state
->old_bs
->drv
->format_name
,
1353 NULL
, -1, flags
, &local_err
, false);
1355 error_propagate(errp
, local_err
);
1360 if (has_snapshot_node_name
) {
1361 options
= qdict_new();
1362 qdict_put(options
, "node-name",
1363 qstring_from_str(snapshot_node_name
));
1366 /* TODO Inherit bs->options or only take explicit options with an
1367 * extended QMP command? */
1368 assert(state
->new_bs
== NULL
);
1369 ret
= bdrv_open(&state
->new_bs
, new_image_file
, NULL
, options
,
1370 flags
| BDRV_O_NO_BACKING
, drv
, &local_err
);
1371 /* We will manually add the backing_hd field to the bs later */
1373 error_propagate(errp
, local_err
);
1377 static void external_snapshot_commit(BlkTransactionState
*common
)
1379 ExternalSnapshotState
*state
=
1380 DO_UPCAST(ExternalSnapshotState
, common
, common
);
1382 /* This removes our old bs and adds the new bs */
1383 bdrv_append(state
->new_bs
, state
->old_bs
);
1384 /* We don't need (or want) to use the transactional
1385 * bdrv_reopen_multiple() across all the entries at once, because we
1386 * don't want to abort all of them if one of them fails the reopen */
1387 bdrv_reopen(state
->new_bs
, state
->new_bs
->open_flags
& ~BDRV_O_RDWR
,
1391 static void external_snapshot_abort(BlkTransactionState
*common
)
1393 ExternalSnapshotState
*state
=
1394 DO_UPCAST(ExternalSnapshotState
, common
, common
);
1395 if (state
->new_bs
) {
1396 bdrv_unref(state
->new_bs
);
1400 typedef struct DriveBackupState
{
1401 BlkTransactionState common
;
1402 BlockDriverState
*bs
;
1406 static void drive_backup_prepare(BlkTransactionState
*common
, Error
**errp
)
1408 DriveBackupState
*state
= DO_UPCAST(DriveBackupState
, common
, common
);
1409 DriveBackup
*backup
;
1410 Error
*local_err
= NULL
;
1412 assert(common
->action
->kind
== TRANSACTION_ACTION_KIND_DRIVE_BACKUP
);
1413 backup
= common
->action
->drive_backup
;
1415 qmp_drive_backup(backup
->device
, backup
->target
,
1416 backup
->has_format
, backup
->format
,
1418 backup
->has_mode
, backup
->mode
,
1419 backup
->has_speed
, backup
->speed
,
1420 backup
->has_on_source_error
, backup
->on_source_error
,
1421 backup
->has_on_target_error
, backup
->on_target_error
,
1424 error_propagate(errp
, local_err
);
1430 state
->bs
= bdrv_find(backup
->device
);
1431 state
->job
= state
->bs
->job
;
1434 static void drive_backup_abort(BlkTransactionState
*common
)
1436 DriveBackupState
*state
= DO_UPCAST(DriveBackupState
, common
, common
);
1437 BlockDriverState
*bs
= state
->bs
;
1439 /* Only cancel if it's the job we started */
1440 if (bs
&& bs
->job
&& bs
->job
== state
->job
) {
1441 block_job_cancel_sync(bs
->job
);
1445 static void abort_prepare(BlkTransactionState
*common
, Error
**errp
)
1447 error_setg(errp
, "Transaction aborted using Abort action");
1450 static void abort_commit(BlkTransactionState
*common
)
1452 g_assert_not_reached(); /* this action never succeeds */
1455 static const BdrvActionOps actions
[] = {
1456 [TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC
] = {
1457 .instance_size
= sizeof(ExternalSnapshotState
),
1458 .prepare
= external_snapshot_prepare
,
1459 .commit
= external_snapshot_commit
,
1460 .abort
= external_snapshot_abort
,
1462 [TRANSACTION_ACTION_KIND_DRIVE_BACKUP
] = {
1463 .instance_size
= sizeof(DriveBackupState
),
1464 .prepare
= drive_backup_prepare
,
1465 .abort
= drive_backup_abort
,
1467 [TRANSACTION_ACTION_KIND_ABORT
] = {
1468 .instance_size
= sizeof(BlkTransactionState
),
1469 .prepare
= abort_prepare
,
1470 .commit
= abort_commit
,
1472 [TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_INTERNAL_SYNC
] = {
1473 .instance_size
= sizeof(InternalSnapshotState
),
1474 .prepare
= internal_snapshot_prepare
,
1475 .abort
= internal_snapshot_abort
,
1480 * 'Atomic' group snapshots. The snapshots are taken as a set, and if any fail
1481 * then we do not pivot any of the devices in the group, and abandon the
1484 void qmp_transaction(TransactionActionList
*dev_list
, Error
**errp
)
1486 TransactionActionList
*dev_entry
= dev_list
;
1487 BlkTransactionState
*state
, *next
;
1488 Error
*local_err
= NULL
;
1490 QSIMPLEQ_HEAD(snap_bdrv_states
, BlkTransactionState
) snap_bdrv_states
;
1491 QSIMPLEQ_INIT(&snap_bdrv_states
);
1493 /* drain all i/o before any snapshots */
1496 /* We don't do anything in this loop that commits us to the snapshot */
1497 while (NULL
!= dev_entry
) {
1498 TransactionAction
*dev_info
= NULL
;
1499 const BdrvActionOps
*ops
;
1501 dev_info
= dev_entry
->value
;
1502 dev_entry
= dev_entry
->next
;
1504 assert(dev_info
->kind
< ARRAY_SIZE(actions
));
1506 ops
= &actions
[dev_info
->kind
];
1507 assert(ops
->instance_size
> 0);
1509 state
= g_malloc0(ops
->instance_size
);
1511 state
->action
= dev_info
;
1512 QSIMPLEQ_INSERT_TAIL(&snap_bdrv_states
, state
, entry
);
1514 state
->ops
->prepare(state
, &local_err
);
1516 error_propagate(errp
, local_err
);
1517 goto delete_and_fail
;
1521 QSIMPLEQ_FOREACH(state
, &snap_bdrv_states
, entry
) {
1522 if (state
->ops
->commit
) {
1523 state
->ops
->commit(state
);
1532 * failure, and it is all-or-none; abandon each new bs, and keep using
1533 * the original bs for all images
1535 QSIMPLEQ_FOREACH(state
, &snap_bdrv_states
, entry
) {
1536 if (state
->ops
->abort
) {
1537 state
->ops
->abort(state
);
1541 QSIMPLEQ_FOREACH_SAFE(state
, &snap_bdrv_states
, entry
, next
) {
1542 if (state
->ops
->clean
) {
1543 state
->ops
->clean(state
);
1550 static void eject_device(BlockDriverState
*bs
, int force
, Error
**errp
)
1552 if (bdrv_op_is_blocked(bs
, BLOCK_OP_TYPE_EJECT
, errp
)) {
1555 if (!bdrv_dev_has_removable_media(bs
)) {
1556 error_setg(errp
, "Device '%s' is not removable",
1557 bdrv_get_device_name(bs
));
1561 if (bdrv_dev_is_medium_locked(bs
) && !bdrv_dev_is_tray_open(bs
)) {
1562 bdrv_dev_eject_request(bs
, force
);
1564 error_setg(errp
, "Device '%s' is locked",
1565 bdrv_get_device_name(bs
));
1573 void qmp_eject(const char *device
, bool has_force
, bool force
, Error
**errp
)
1575 BlockDriverState
*bs
;
1577 bs
= bdrv_find(device
);
1579 error_set(errp
, QERR_DEVICE_NOT_FOUND
, device
);
1583 eject_device(bs
, force
, errp
);
1586 void qmp_block_passwd(bool has_device
, const char *device
,
1587 bool has_node_name
, const char *node_name
,
1588 const char *password
, Error
**errp
)
1590 Error
*local_err
= NULL
;
1591 BlockDriverState
*bs
;
1594 bs
= bdrv_lookup_bs(has_device
? device
: NULL
,
1595 has_node_name
? node_name
: NULL
,
1598 error_propagate(errp
, local_err
);
1602 err
= bdrv_set_key(bs
, password
);
1603 if (err
== -EINVAL
) {
1604 error_set(errp
, QERR_DEVICE_NOT_ENCRYPTED
, bdrv_get_device_name(bs
));
1606 } else if (err
< 0) {
1607 error_set(errp
, QERR_INVALID_PASSWORD
);
1612 static void qmp_bdrv_open_encrypted(BlockDriverState
*bs
, const char *filename
,
1613 int bdrv_flags
, BlockDriver
*drv
,
1614 const char *password
, Error
**errp
)
1616 Error
*local_err
= NULL
;
1619 ret
= bdrv_open(&bs
, filename
, NULL
, NULL
, bdrv_flags
, drv
, &local_err
);
1621 error_propagate(errp
, local_err
);
1625 if (bdrv_key_required(bs
)) {
1627 if (bdrv_set_key(bs
, password
) < 0) {
1628 error_set(errp
, QERR_INVALID_PASSWORD
);
1631 error_set(errp
, QERR_DEVICE_ENCRYPTED
, bdrv_get_device_name(bs
),
1632 bdrv_get_encrypted_filename(bs
));
1634 } else if (password
) {
1635 error_set(errp
, QERR_DEVICE_NOT_ENCRYPTED
, bdrv_get_device_name(bs
));
1639 void qmp_change_blockdev(const char *device
, const char *filename
,
1640 const char *format
, Error
**errp
)
1642 BlockDriverState
*bs
;
1643 BlockDriver
*drv
= NULL
;
1647 bs
= bdrv_find(device
);
1649 error_set(errp
, QERR_DEVICE_NOT_FOUND
, device
);
1654 drv
= bdrv_find_whitelisted_format(format
, bs
->read_only
);
1656 error_set(errp
, QERR_INVALID_BLOCK_FORMAT
, format
);
1661 eject_device(bs
, 0, &err
);
1663 error_propagate(errp
, err
);
1667 bdrv_flags
= bdrv_is_read_only(bs
) ? 0 : BDRV_O_RDWR
;
1668 bdrv_flags
|= bdrv_is_snapshot(bs
) ? BDRV_O_SNAPSHOT
: 0;
1670 qmp_bdrv_open_encrypted(bs
, filename
, bdrv_flags
, drv
, NULL
, errp
);
1673 /* throttling disk I/O limits */
1674 void qmp_block_set_io_throttle(const char *device
, int64_t bps
, int64_t bps_rd
,
1681 bool has_bps_rd_max
,
1683 bool has_bps_wr_max
,
1687 bool has_iops_rd_max
,
1688 int64_t iops_rd_max
,
1689 bool has_iops_wr_max
,
1690 int64_t iops_wr_max
,
1692 int64_t iops_size
, Error
**errp
)
1695 BlockDriverState
*bs
;
1696 AioContext
*aio_context
;
1698 bs
= bdrv_find(device
);
1700 error_set(errp
, QERR_DEVICE_NOT_FOUND
, device
);
1704 memset(&cfg
, 0, sizeof(cfg
));
1705 cfg
.buckets
[THROTTLE_BPS_TOTAL
].avg
= bps
;
1706 cfg
.buckets
[THROTTLE_BPS_READ
].avg
= bps_rd
;
1707 cfg
.buckets
[THROTTLE_BPS_WRITE
].avg
= bps_wr
;
1709 cfg
.buckets
[THROTTLE_OPS_TOTAL
].avg
= iops
;
1710 cfg
.buckets
[THROTTLE_OPS_READ
].avg
= iops_rd
;
1711 cfg
.buckets
[THROTTLE_OPS_WRITE
].avg
= iops_wr
;
1714 cfg
.buckets
[THROTTLE_BPS_TOTAL
].max
= bps_max
;
1716 if (has_bps_rd_max
) {
1717 cfg
.buckets
[THROTTLE_BPS_READ
].max
= bps_rd_max
;
1719 if (has_bps_wr_max
) {
1720 cfg
.buckets
[THROTTLE_BPS_WRITE
].max
= bps_wr_max
;
1723 cfg
.buckets
[THROTTLE_OPS_TOTAL
].max
= iops_max
;
1725 if (has_iops_rd_max
) {
1726 cfg
.buckets
[THROTTLE_OPS_READ
].max
= iops_rd_max
;
1728 if (has_iops_wr_max
) {
1729 cfg
.buckets
[THROTTLE_OPS_WRITE
].max
= iops_wr_max
;
1732 if (has_iops_size
) {
1733 cfg
.op_size
= iops_size
;
1736 if (!check_throttle_config(&cfg
, errp
)) {
1740 aio_context
= bdrv_get_aio_context(bs
);
1741 aio_context_acquire(aio_context
);
1743 if (!bs
->io_limits_enabled
&& throttle_enabled(&cfg
)) {
1744 bdrv_io_limits_enable(bs
);
1745 } else if (bs
->io_limits_enabled
&& !throttle_enabled(&cfg
)) {
1746 bdrv_io_limits_disable(bs
);
1749 if (bs
->io_limits_enabled
) {
1750 bdrv_set_io_limits(bs
, &cfg
);
1753 aio_context_release(aio_context
);
1756 int do_drive_del(Monitor
*mon
, const QDict
*qdict
, QObject
**ret_data
)
1758 const char *id
= qdict_get_str(qdict
, "id");
1759 BlockDriverState
*bs
;
1760 Error
*local_err
= NULL
;
1764 error_report("Device '%s' not found", id
);
1767 if (bdrv_op_is_blocked(bs
, BLOCK_OP_TYPE_DRIVE_DEL
, &local_err
)) {
1768 error_report("%s", error_get_pretty(local_err
));
1769 error_free(local_err
);
1773 /* quiesce block driver; prevent further io */
1778 /* if we have a device attached to this BlockDriverState
1779 * then we need to make the drive anonymous until the device
1780 * can be removed. If this is a drive with no device backing
1781 * then we can just get rid of the block driver state right here.
1783 if (bdrv_get_attached_dev(bs
)) {
1786 /* Further I/O must not pause the guest */
1787 bdrv_set_on_error(bs
, BLOCKDEV_ON_ERROR_REPORT
,
1788 BLOCKDEV_ON_ERROR_REPORT
);
1790 drive_del(drive_get_by_blockdev(bs
));
1796 void qmp_block_resize(bool has_device
, const char *device
,
1797 bool has_node_name
, const char *node_name
,
1798 int64_t size
, Error
**errp
)
1800 Error
*local_err
= NULL
;
1801 BlockDriverState
*bs
;
1804 bs
= bdrv_lookup_bs(has_device
? device
: NULL
,
1805 has_node_name
? node_name
: NULL
,
1808 error_propagate(errp
, local_err
);
1812 if (!bdrv_is_first_non_filter(bs
)) {
1813 error_set(errp
, QERR_FEATURE_DISABLED
, "resize");
1818 error_set(errp
, QERR_INVALID_PARAMETER_VALUE
, "size", "a >0 size");
1822 if (bdrv_op_is_blocked(bs
, BLOCK_OP_TYPE_RESIZE
, NULL
)) {
1823 error_set(errp
, QERR_DEVICE_IN_USE
, device
);
1827 /* complete all in-flight operations before resizing the device */
1830 ret
= bdrv_truncate(bs
, size
);
1835 error_set(errp
, QERR_DEVICE_HAS_NO_MEDIUM
, device
);
1838 error_set(errp
, QERR_UNSUPPORTED
);
1841 error_set(errp
, QERR_DEVICE_IS_READ_ONLY
, device
);
1844 error_set(errp
, QERR_DEVICE_IN_USE
, device
);
1847 error_setg_errno(errp
, -ret
, "Could not resize");
1852 static void block_job_cb(void *opaque
, int ret
)
1854 BlockDriverState
*bs
= opaque
;
1855 const char *msg
= NULL
;
1857 trace_block_job_cb(bs
, bs
->job
, ret
);
1862 msg
= strerror(-ret
);
1865 if (block_job_is_cancelled(bs
->job
)) {
1866 block_job_event_cancelled(bs
->job
);
1868 block_job_event_completed(bs
->job
, msg
);
1871 bdrv_put_ref_bh_schedule(bs
);
1874 void qmp_block_stream(const char *device
, bool has_base
,
1875 const char *base
, bool has_speed
, int64_t speed
,
1876 bool has_on_error
, BlockdevOnError on_error
,
1879 BlockDriverState
*bs
;
1880 BlockDriverState
*base_bs
= NULL
;
1881 Error
*local_err
= NULL
;
1883 if (!has_on_error
) {
1884 on_error
= BLOCKDEV_ON_ERROR_REPORT
;
1887 bs
= bdrv_find(device
);
1889 error_set(errp
, QERR_DEVICE_NOT_FOUND
, device
);
1893 if (bdrv_op_is_blocked(bs
, BLOCK_OP_TYPE_STREAM
, errp
)) {
1898 base_bs
= bdrv_find_backing_image(bs
, base
);
1899 if (base_bs
== NULL
) {
1900 error_set(errp
, QERR_BASE_NOT_FOUND
, base
);
1905 stream_start(bs
, base_bs
, base
, has_speed
? speed
: 0,
1906 on_error
, block_job_cb
, bs
, &local_err
);
1908 error_propagate(errp
, local_err
);
1912 trace_qmp_block_stream(bs
, bs
->job
);
1915 void qmp_block_commit(const char *device
,
1916 bool has_base
, const char *base
, const char *top
,
1917 bool has_speed
, int64_t speed
,
1920 BlockDriverState
*bs
;
1921 BlockDriverState
*base_bs
, *top_bs
;
1922 Error
*local_err
= NULL
;
1923 /* This will be part of the QMP command, if/when the
1924 * BlockdevOnError change for blkmirror makes it in
1926 BlockdevOnError on_error
= BLOCKDEV_ON_ERROR_REPORT
;
1932 /* drain all i/o before commits */
1935 bs
= bdrv_find(device
);
1937 error_set(errp
, QERR_DEVICE_NOT_FOUND
, device
);
1941 if (bdrv_op_is_blocked(bs
, BLOCK_OP_TYPE_COMMIT
, errp
)) {
1945 /* default top_bs is the active layer */
1949 if (strcmp(bs
->filename
, top
) != 0) {
1950 top_bs
= bdrv_find_backing_image(bs
, top
);
1954 if (top_bs
== NULL
) {
1955 error_setg(errp
, "Top image file %s not found", top
? top
: "NULL");
1959 if (has_base
&& base
) {
1960 base_bs
= bdrv_find_backing_image(top_bs
, base
);
1962 base_bs
= bdrv_find_base(top_bs
);
1965 if (base_bs
== NULL
) {
1966 error_set(errp
, QERR_BASE_NOT_FOUND
, base
? base
: "NULL");
1971 commit_active_start(bs
, base_bs
, speed
, on_error
, block_job_cb
,
1974 commit_start(bs
, base_bs
, top_bs
, speed
, on_error
, block_job_cb
, bs
,
1977 if (local_err
!= NULL
) {
1978 error_propagate(errp
, local_err
);
1983 void qmp_drive_backup(const char *device
, const char *target
,
1984 bool has_format
, const char *format
,
1985 enum MirrorSyncMode sync
,
1986 bool has_mode
, enum NewImageMode mode
,
1987 bool has_speed
, int64_t speed
,
1988 bool has_on_source_error
, BlockdevOnError on_source_error
,
1989 bool has_on_target_error
, BlockdevOnError on_target_error
,
1992 BlockDriverState
*bs
;
1993 BlockDriverState
*target_bs
;
1994 BlockDriverState
*source
= NULL
;
1995 BlockDriver
*drv
= NULL
;
1996 Error
*local_err
= NULL
;
2004 if (!has_on_source_error
) {
2005 on_source_error
= BLOCKDEV_ON_ERROR_REPORT
;
2007 if (!has_on_target_error
) {
2008 on_target_error
= BLOCKDEV_ON_ERROR_REPORT
;
2011 mode
= NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
2014 bs
= bdrv_find(device
);
2016 error_set(errp
, QERR_DEVICE_NOT_FOUND
, device
);
2020 if (!bdrv_is_inserted(bs
)) {
2021 error_set(errp
, QERR_DEVICE_HAS_NO_MEDIUM
, device
);
2026 format
= mode
== NEW_IMAGE_MODE_EXISTING
? NULL
: bs
->drv
->format_name
;
2029 drv
= bdrv_find_format(format
);
2031 error_set(errp
, QERR_INVALID_BLOCK_FORMAT
, format
);
2036 if (bdrv_op_is_blocked(bs
, BLOCK_OP_TYPE_BACKUP_SOURCE
, errp
)) {
2040 flags
= bs
->open_flags
| BDRV_O_RDWR
;
2042 /* See if we have a backing HD we can use to create our new image
2044 if (sync
== MIRROR_SYNC_MODE_TOP
) {
2045 source
= bs
->backing_hd
;
2047 sync
= MIRROR_SYNC_MODE_FULL
;
2050 if (sync
== MIRROR_SYNC_MODE_NONE
) {
2054 size
= bdrv_getlength(bs
);
2056 error_setg_errno(errp
, -size
, "bdrv_getlength failed");
2060 if (mode
!= NEW_IMAGE_MODE_EXISTING
) {
2061 assert(format
&& drv
);
2063 bdrv_img_create(target
, format
, source
->filename
,
2064 source
->drv
->format_name
, NULL
,
2065 size
, flags
, &local_err
, false);
2067 bdrv_img_create(target
, format
, NULL
, NULL
, NULL
,
2068 size
, flags
, &local_err
, false);
2073 error_propagate(errp
, local_err
);
2078 ret
= bdrv_open(&target_bs
, target
, NULL
, NULL
, flags
, drv
, &local_err
);
2080 error_propagate(errp
, local_err
);
2084 backup_start(bs
, target_bs
, speed
, sync
, on_source_error
, on_target_error
,
2085 block_job_cb
, bs
, &local_err
);
2086 if (local_err
!= NULL
) {
2087 bdrv_unref(target_bs
);
2088 error_propagate(errp
, local_err
);
2093 BlockDeviceInfoList
*qmp_query_named_block_nodes(Error
**errp
)
2095 return bdrv_named_nodes_list();
2098 #define DEFAULT_MIRROR_BUF_SIZE (10 << 20)
2100 void qmp_drive_mirror(const char *device
, const char *target
,
2101 bool has_format
, const char *format
,
2102 bool has_node_name
, const char *node_name
,
2103 bool has_replaces
, const char *replaces
,
2104 enum MirrorSyncMode sync
,
2105 bool has_mode
, enum NewImageMode mode
,
2106 bool has_speed
, int64_t speed
,
2107 bool has_granularity
, uint32_t granularity
,
2108 bool has_buf_size
, int64_t buf_size
,
2109 bool has_on_source_error
, BlockdevOnError on_source_error
,
2110 bool has_on_target_error
, BlockdevOnError on_target_error
,
2113 BlockDriverState
*bs
;
2114 BlockDriverState
*source
, *target_bs
;
2115 BlockDriver
*drv
= NULL
;
2116 Error
*local_err
= NULL
;
2117 QDict
*options
= NULL
;
2125 if (!has_on_source_error
) {
2126 on_source_error
= BLOCKDEV_ON_ERROR_REPORT
;
2128 if (!has_on_target_error
) {
2129 on_target_error
= BLOCKDEV_ON_ERROR_REPORT
;
2132 mode
= NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
2134 if (!has_granularity
) {
2137 if (!has_buf_size
) {
2138 buf_size
= DEFAULT_MIRROR_BUF_SIZE
;
2141 if (granularity
!= 0 && (granularity
< 512 || granularity
> 1048576 * 64)) {
2142 error_set(errp
, QERR_INVALID_PARAMETER
, device
);
2145 if (granularity
& (granularity
- 1)) {
2146 error_set(errp
, QERR_INVALID_PARAMETER
, device
);
2150 bs
= bdrv_find(device
);
2152 error_set(errp
, QERR_DEVICE_NOT_FOUND
, device
);
2156 if (!bdrv_is_inserted(bs
)) {
2157 error_set(errp
, QERR_DEVICE_HAS_NO_MEDIUM
, device
);
2162 format
= mode
== NEW_IMAGE_MODE_EXISTING
? NULL
: bs
->drv
->format_name
;
2165 drv
= bdrv_find_format(format
);
2167 error_set(errp
, QERR_INVALID_BLOCK_FORMAT
, format
);
2172 if (bdrv_op_is_blocked(bs
, BLOCK_OP_TYPE_MIRROR
, errp
)) {
2176 flags
= bs
->open_flags
| BDRV_O_RDWR
;
2177 source
= bs
->backing_hd
;
2178 if (!source
&& sync
== MIRROR_SYNC_MODE_TOP
) {
2179 sync
= MIRROR_SYNC_MODE_FULL
;
2181 if (sync
== MIRROR_SYNC_MODE_NONE
) {
2185 size
= bdrv_getlength(bs
);
2187 error_setg_errno(errp
, -size
, "bdrv_getlength failed");
2192 BlockDriverState
*to_replace_bs
;
2194 if (!has_node_name
) {
2195 error_setg(errp
, "a node-name must be provided when replacing a"
2196 " named node of the graph");
2200 to_replace_bs
= check_to_replace_node(replaces
, &local_err
);
2202 if (!to_replace_bs
) {
2203 error_propagate(errp
, local_err
);
2207 if (size
!= bdrv_getlength(to_replace_bs
)) {
2208 error_setg(errp
, "cannot replace image with a mirror image of "
2214 if ((sync
== MIRROR_SYNC_MODE_FULL
|| !source
)
2215 && mode
!= NEW_IMAGE_MODE_EXISTING
)
2217 /* create new image w/o backing file */
2218 assert(format
&& drv
);
2219 bdrv_img_create(target
, format
,
2220 NULL
, NULL
, NULL
, size
, flags
, &local_err
, false);
2223 case NEW_IMAGE_MODE_EXISTING
:
2225 case NEW_IMAGE_MODE_ABSOLUTE_PATHS
:
2226 /* create new image with backing file */
2227 bdrv_img_create(target
, format
,
2229 source
->drv
->format_name
,
2230 NULL
, size
, flags
, &local_err
, false);
2238 error_propagate(errp
, local_err
);
2242 if (has_node_name
) {
2243 options
= qdict_new();
2244 qdict_put(options
, "node-name", qstring_from_str(node_name
));
2247 /* Mirroring takes care of copy-on-write using the source's backing
2251 ret
= bdrv_open(&target_bs
, target
, NULL
, options
,
2252 flags
| BDRV_O_NO_BACKING
, drv
, &local_err
);
2254 error_propagate(errp
, local_err
);
2258 /* pass the node name to replace to mirror start since it's loose coupling
2259 * and will allow to check whether the node still exist at mirror completion
2261 mirror_start(bs
, target_bs
,
2262 has_replaces
? replaces
: NULL
,
2263 speed
, granularity
, buf_size
, sync
,
2264 on_source_error
, on_target_error
,
2265 block_job_cb
, bs
, &local_err
);
2266 if (local_err
!= NULL
) {
2267 bdrv_unref(target_bs
);
2268 error_propagate(errp
, local_err
);
2273 static BlockJob
*find_block_job(const char *device
)
2275 BlockDriverState
*bs
;
2277 bs
= bdrv_find(device
);
2278 if (!bs
|| !bs
->job
) {
2284 void qmp_block_job_set_speed(const char *device
, int64_t speed
, Error
**errp
)
2286 BlockJob
*job
= find_block_job(device
);
2289 error_set(errp
, QERR_BLOCK_JOB_NOT_ACTIVE
, device
);
2293 block_job_set_speed(job
, speed
, errp
);
2296 void qmp_block_job_cancel(const char *device
,
2297 bool has_force
, bool force
, Error
**errp
)
2299 BlockJob
*job
= find_block_job(device
);
2306 error_set(errp
, QERR_BLOCK_JOB_NOT_ACTIVE
, device
);
2309 if (job
->paused
&& !force
) {
2310 error_setg(errp
, "The block job for device '%s' is currently paused",
2315 trace_qmp_block_job_cancel(job
);
2316 block_job_cancel(job
);
2319 void qmp_block_job_pause(const char *device
, Error
**errp
)
2321 BlockJob
*job
= find_block_job(device
);
2324 error_set(errp
, QERR_BLOCK_JOB_NOT_ACTIVE
, device
);
2328 trace_qmp_block_job_pause(job
);
2329 block_job_pause(job
);
2332 void qmp_block_job_resume(const char *device
, Error
**errp
)
2334 BlockJob
*job
= find_block_job(device
);
2337 error_set(errp
, QERR_BLOCK_JOB_NOT_ACTIVE
, device
);
2341 trace_qmp_block_job_resume(job
);
2342 block_job_resume(job
);
2345 void qmp_block_job_complete(const char *device
, Error
**errp
)
2347 BlockJob
*job
= find_block_job(device
);
2350 error_set(errp
, QERR_BLOCK_JOB_NOT_ACTIVE
, device
);
2354 trace_qmp_block_job_complete(job
);
2355 block_job_complete(job
, errp
);
2358 void qmp_blockdev_add(BlockdevOptions
*options
, Error
**errp
)
2360 QmpOutputVisitor
*ov
= qmp_output_visitor_new();
2364 Error
*local_err
= NULL
;
2366 /* Require an ID in the top level */
2367 if (!options
->has_id
) {
2368 error_setg(errp
, "Block device needs an ID");
2372 /* TODO Sort it out in raw-posix and drive_new(): Reject aio=native with
2373 * cache.direct=false instead of silently switching to aio=threads, except
2374 * when called from drive_new().
2376 * For now, simply forbidding the combination for all drivers will do. */
2377 if (options
->has_aio
&& options
->aio
== BLOCKDEV_AIO_OPTIONS_NATIVE
) {
2378 bool direct
= options
->has_cache
&&
2379 options
->cache
->has_direct
&&
2380 options
->cache
->direct
;
2382 error_setg(errp
, "aio=native requires cache.direct=true");
2387 visit_type_BlockdevOptions(qmp_output_get_visitor(ov
),
2388 &options
, NULL
, &local_err
);
2390 error_propagate(errp
, local_err
);
2394 obj
= qmp_output_get_qobject(ov
);
2395 qdict
= qobject_to_qdict(obj
);
2397 qdict_flatten(qdict
);
2399 dinfo
= blockdev_init(NULL
, qdict
, &local_err
);
2401 error_propagate(errp
, local_err
);
2405 if (bdrv_key_required(dinfo
->bdrv
)) {
2407 error_setg(errp
, "blockdev-add doesn't support encrypted devices");
2412 qmp_output_visitor_cleanup(ov
);
2415 static void do_qmp_query_block_jobs_one(void *opaque
, BlockDriverState
*bs
)
2417 BlockJobInfoList
**prev
= opaque
;
2418 BlockJob
*job
= bs
->job
;
2421 BlockJobInfoList
*elem
= g_new0(BlockJobInfoList
, 1);
2422 elem
->value
= block_job_query(bs
->job
);
2423 (*prev
)->next
= elem
;
2428 BlockJobInfoList
*qmp_query_block_jobs(Error
**errp
)
2430 /* Dummy is a fake list element for holding the head pointer */
2431 BlockJobInfoList dummy
= {};
2432 BlockJobInfoList
*prev
= &dummy
;
2433 bdrv_iterate(do_qmp_query_block_jobs_one
, &prev
);
2437 QemuOptsList qemu_common_drive_opts
= {
2439 .head
= QTAILQ_HEAD_INITIALIZER(qemu_common_drive_opts
.head
),
2443 .type
= QEMU_OPT_BOOL
,
2444 .help
= "enable/disable snapshot mode",
2447 .type
= QEMU_OPT_STRING
,
2448 .help
= "discard operation (ignore/off, unmap/on)",
2450 .name
= "cache.writeback",
2451 .type
= QEMU_OPT_BOOL
,
2452 .help
= "enables writeback mode for any caches",
2454 .name
= "cache.direct",
2455 .type
= QEMU_OPT_BOOL
,
2456 .help
= "enables use of O_DIRECT (bypass the host page cache)",
2458 .name
= "cache.no-flush",
2459 .type
= QEMU_OPT_BOOL
,
2460 .help
= "ignore any flush requests for the device",
2463 .type
= QEMU_OPT_STRING
,
2464 .help
= "host AIO implementation (threads, native)",
2467 .type
= QEMU_OPT_STRING
,
2468 .help
= "disk format (raw, qcow2, ...)",
2471 .type
= QEMU_OPT_STRING
,
2472 .help
= "read error action",
2475 .type
= QEMU_OPT_STRING
,
2476 .help
= "write error action",
2478 .name
= "read-only",
2479 .type
= QEMU_OPT_BOOL
,
2480 .help
= "open drive file as read-only",
2482 .name
= "throttling.iops-total",
2483 .type
= QEMU_OPT_NUMBER
,
2484 .help
= "limit total I/O operations per second",
2486 .name
= "throttling.iops-read",
2487 .type
= QEMU_OPT_NUMBER
,
2488 .help
= "limit read operations per second",
2490 .name
= "throttling.iops-write",
2491 .type
= QEMU_OPT_NUMBER
,
2492 .help
= "limit write operations per second",
2494 .name
= "throttling.bps-total",
2495 .type
= QEMU_OPT_NUMBER
,
2496 .help
= "limit total bytes per second",
2498 .name
= "throttling.bps-read",
2499 .type
= QEMU_OPT_NUMBER
,
2500 .help
= "limit read bytes per second",
2502 .name
= "throttling.bps-write",
2503 .type
= QEMU_OPT_NUMBER
,
2504 .help
= "limit write bytes per second",
2506 .name
= "throttling.iops-total-max",
2507 .type
= QEMU_OPT_NUMBER
,
2508 .help
= "I/O operations burst",
2510 .name
= "throttling.iops-read-max",
2511 .type
= QEMU_OPT_NUMBER
,
2512 .help
= "I/O operations read burst",
2514 .name
= "throttling.iops-write-max",
2515 .type
= QEMU_OPT_NUMBER
,
2516 .help
= "I/O operations write burst",
2518 .name
= "throttling.bps-total-max",
2519 .type
= QEMU_OPT_NUMBER
,
2520 .help
= "total bytes burst",
2522 .name
= "throttling.bps-read-max",
2523 .type
= QEMU_OPT_NUMBER
,
2524 .help
= "total bytes read burst",
2526 .name
= "throttling.bps-write-max",
2527 .type
= QEMU_OPT_NUMBER
,
2528 .help
= "total bytes write burst",
2530 .name
= "throttling.iops-size",
2531 .type
= QEMU_OPT_NUMBER
,
2532 .help
= "when limiting by iops max size of an I/O in bytes",
2534 .name
= "copy-on-read",
2535 .type
= QEMU_OPT_BOOL
,
2536 .help
= "copy read data from backing file into image file",
2538 .name
= "detect-zeroes",
2539 .type
= QEMU_OPT_STRING
,
2540 .help
= "try to optimize zero writes (off, on, unmap)",
2542 { /* end of list */ }
2546 QemuOptsList qemu_drive_opts
= {
2548 .head
= QTAILQ_HEAD_INITIALIZER(qemu_drive_opts
.head
),
2551 * no elements => accept any params
2552 * validation will happen later
2554 { /* end of list */ }