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 "qapi/qmp/qerror.h"
38 #include "qemu/option.h"
39 #include "qemu/config-file.h"
40 #include "qapi/qmp/types.h"
41 #include "sysemu/sysemu.h"
42 #include "block/block_int.h"
43 #include "qmp-commands.h"
45 #include "sysemu/arch_init.h"
47 static QTAILQ_HEAD(drivelist
, DriveInfo
) drives
= QTAILQ_HEAD_INITIALIZER(drives
);
48 extern QemuOptsList qemu_common_drive_opts
;
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
);
93 block_job_cancel(bs
->job
);
100 void blockdev_auto_del(BlockDriverState
*bs
)
102 DriveInfo
*dinfo
= drive_get_by_blockdev(bs
);
104 if (dinfo
&& dinfo
->auto_del
) {
105 drive_put_ref(dinfo
);
109 static int drive_index_to_bus_id(BlockInterfaceType type
, int index
)
111 int max_devs
= if_max_devs
[type
];
112 return max_devs
? index
/ max_devs
: 0;
115 static int drive_index_to_unit_id(BlockInterfaceType type
, int index
)
117 int max_devs
= if_max_devs
[type
];
118 return max_devs
? index
% max_devs
: index
;
121 QemuOpts
*drive_def(const char *optstr
)
123 return qemu_opts_parse(qemu_find_opts("drive"), optstr
, 0);
126 QemuOpts
*drive_add(BlockInterfaceType type
, int index
, const char *file
,
132 opts
= drive_def(optstr
);
136 if (type
!= IF_DEFAULT
) {
137 qemu_opt_set(opts
, "if", if_name
[type
]);
140 snprintf(buf
, sizeof(buf
), "%d", index
);
141 qemu_opt_set(opts
, "index", buf
);
144 qemu_opt_set(opts
, "file", file
);
148 DriveInfo
*drive_get(BlockInterfaceType type
, int bus
, int unit
)
152 /* seek interface, bus and unit */
154 QTAILQ_FOREACH(dinfo
, &drives
, next
) {
155 if (dinfo
->type
== type
&&
164 DriveInfo
*drive_get_by_index(BlockInterfaceType type
, int index
)
166 return drive_get(type
,
167 drive_index_to_bus_id(type
, index
),
168 drive_index_to_unit_id(type
, index
));
171 int drive_get_max_bus(BlockInterfaceType type
)
177 QTAILQ_FOREACH(dinfo
, &drives
, next
) {
178 if(dinfo
->type
== type
&&
179 dinfo
->bus
> max_bus
)
180 max_bus
= dinfo
->bus
;
185 /* Get a block device. This should only be used for single-drive devices
186 (e.g. SD/Floppy/MTD). Multi-disk devices (scsi/ide) should use the
188 DriveInfo
*drive_get_next(BlockInterfaceType type
)
190 static int next_block_unit
[IF_COUNT
];
192 return drive_get(type
, 0, next_block_unit
[type
]++);
195 DriveInfo
*drive_get_by_blockdev(BlockDriverState
*bs
)
199 QTAILQ_FOREACH(dinfo
, &drives
, next
) {
200 if (dinfo
->bdrv
== bs
) {
207 static void bdrv_format_print(void *opaque
, const char *name
)
209 error_printf(" %s", name
);
212 static void drive_uninit(DriveInfo
*dinfo
)
214 qemu_opts_del(dinfo
->opts
);
215 bdrv_delete(dinfo
->bdrv
);
217 QTAILQ_REMOVE(&drives
, dinfo
, next
);
218 g_free(dinfo
->serial
);
222 void drive_put_ref(DriveInfo
*dinfo
)
224 assert(dinfo
->refcount
);
225 if (--dinfo
->refcount
== 0) {
230 void drive_get_ref(DriveInfo
*dinfo
)
240 static void drive_put_ref_bh(void *opaque
)
242 DrivePutRefBH
*s
= opaque
;
244 drive_put_ref(s
->dinfo
);
245 qemu_bh_delete(s
->bh
);
250 * Release a drive reference in a BH
252 * It is not possible to use drive_put_ref() from a callback function when the
253 * callers still need the drive. In such cases we schedule a BH to release the
256 static void drive_put_ref_bh_schedule(DriveInfo
*dinfo
)
260 s
= g_new(DrivePutRefBH
, 1);
261 s
->bh
= qemu_bh_new(drive_put_ref_bh
, s
);
263 qemu_bh_schedule(s
->bh
);
266 static int parse_block_error_action(const char *buf
, bool is_read
)
268 if (!strcmp(buf
, "ignore")) {
269 return BLOCKDEV_ON_ERROR_IGNORE
;
270 } else if (!is_read
&& !strcmp(buf
, "enospc")) {
271 return BLOCKDEV_ON_ERROR_ENOSPC
;
272 } else if (!strcmp(buf
, "stop")) {
273 return BLOCKDEV_ON_ERROR_STOP
;
274 } else if (!strcmp(buf
, "report")) {
275 return BLOCKDEV_ON_ERROR_REPORT
;
277 error_report("'%s' invalid %s error action",
278 buf
, is_read
? "read" : "write");
283 static bool do_check_io_limits(BlockIOLimit
*io_limits
, Error
**errp
)
290 bps_flag
= (io_limits
->bps
[BLOCK_IO_LIMIT_TOTAL
] != 0)
291 && ((io_limits
->bps
[BLOCK_IO_LIMIT_READ
] != 0)
292 || (io_limits
->bps
[BLOCK_IO_LIMIT_WRITE
] != 0));
293 iops_flag
= (io_limits
->iops
[BLOCK_IO_LIMIT_TOTAL
] != 0)
294 && ((io_limits
->iops
[BLOCK_IO_LIMIT_READ
] != 0)
295 || (io_limits
->iops
[BLOCK_IO_LIMIT_WRITE
] != 0));
296 if (bps_flag
|| iops_flag
) {
297 error_setg(errp
, "bps(iops) and bps_rd/bps_wr(iops_rd/iops_wr) "
298 "cannot be used at the same time");
302 if (io_limits
->bps
[BLOCK_IO_LIMIT_TOTAL
] < 0 ||
303 io_limits
->bps
[BLOCK_IO_LIMIT_WRITE
] < 0 ||
304 io_limits
->bps
[BLOCK_IO_LIMIT_READ
] < 0 ||
305 io_limits
->iops
[BLOCK_IO_LIMIT_TOTAL
] < 0 ||
306 io_limits
->iops
[BLOCK_IO_LIMIT_WRITE
] < 0 ||
307 io_limits
->iops
[BLOCK_IO_LIMIT_READ
] < 0) {
308 error_setg(errp
, "bps and iops values must be 0 or greater");
315 DriveInfo
*drive_init(QemuOpts
*all_opts
, BlockInterfaceType block_default_type
)
318 const char *file
= NULL
;
320 const char *mediastr
= "";
321 BlockInterfaceType type
;
322 enum { MEDIA_DISK
, MEDIA_CDROM
} media
;
324 int cyls
, heads
, secs
, translation
;
325 BlockDriver
*drv
= NULL
;
330 int on_read_error
, on_write_error
;
333 BlockIOLimit io_limits
;
342 translation
= BIOS_ATA_TRANSLATION_AUTO
;
345 /* Check common options by copying from all_opts to opts, all other options
346 * are stored in bs_opts. */
347 id
= qemu_opts_id(all_opts
);
348 opts
= qemu_opts_create(&qemu_common_drive_opts
, id
, 1, &error
);
349 if (error_is_set(&error
)) {
350 qerror_report_err(error
);
355 bs_opts
= qdict_new();
356 qemu_opts_to_qdict(all_opts
, bs_opts
);
357 qemu_opts_absorb_qdict(opts
, bs_opts
, &error
);
358 if (error_is_set(&error
)) {
359 qerror_report_err(error
);
365 qdict_del(bs_opts
, "id");
368 /* extract parameters */
369 bus_id
= qemu_opt_get_number(opts
, "bus", 0);
370 unit_id
= qemu_opt_get_number(opts
, "unit", -1);
371 index
= qemu_opt_get_number(opts
, "index", -1);
373 cyls
= qemu_opt_get_number(opts
, "cyls", 0);
374 heads
= qemu_opt_get_number(opts
, "heads", 0);
375 secs
= qemu_opt_get_number(opts
, "secs", 0);
377 snapshot
= qemu_opt_get_bool(opts
, "snapshot", 0);
378 ro
= qemu_opt_get_bool(opts
, "readonly", 0);
379 copy_on_read
= qemu_opt_get_bool(opts
, "copy-on-read", false);
381 file
= qemu_opt_get(opts
, "file");
382 serial
= qemu_opt_get(opts
, "serial");
384 if ((buf
= qemu_opt_get(opts
, "if")) != NULL
) {
385 for (type
= 0; type
< IF_COUNT
&& strcmp(buf
, if_name
[type
]); type
++)
387 if (type
== IF_COUNT
) {
388 error_report("unsupported bus type '%s'", buf
);
392 type
= block_default_type
;
395 max_devs
= if_max_devs
[type
];
397 if (cyls
|| heads
|| secs
) {
399 error_report("invalid physical cyls number");
403 error_report("invalid physical heads number");
407 error_report("invalid physical secs number");
412 if ((buf
= qemu_opt_get(opts
, "trans")) != NULL
) {
414 error_report("'%s' trans must be used with cyls, heads and secs",
418 if (!strcmp(buf
, "none"))
419 translation
= BIOS_ATA_TRANSLATION_NONE
;
420 else if (!strcmp(buf
, "lba"))
421 translation
= BIOS_ATA_TRANSLATION_LBA
;
422 else if (!strcmp(buf
, "auto"))
423 translation
= BIOS_ATA_TRANSLATION_AUTO
;
425 error_report("'%s' invalid translation type", buf
);
430 if ((buf
= qemu_opt_get(opts
, "media")) != NULL
) {
431 if (!strcmp(buf
, "disk")) {
433 } else if (!strcmp(buf
, "cdrom")) {
434 if (cyls
|| secs
|| heads
) {
435 error_report("CHS can't be set with media=%s", buf
);
440 error_report("'%s' invalid media", buf
);
445 if ((buf
= qemu_opt_get(opts
, "discard")) != NULL
) {
446 if (bdrv_parse_discard_flags(buf
, &bdrv_flags
) != 0) {
447 error_report("invalid discard option");
452 bdrv_flags
|= BDRV_O_CACHE_WB
;
453 if ((buf
= qemu_opt_get(opts
, "cache")) != NULL
) {
454 if (bdrv_parse_cache_flags(buf
, &bdrv_flags
) != 0) {
455 error_report("invalid cache option");
460 #ifdef CONFIG_LINUX_AIO
461 if ((buf
= qemu_opt_get(opts
, "aio")) != NULL
) {
462 if (!strcmp(buf
, "native")) {
463 bdrv_flags
|= BDRV_O_NATIVE_AIO
;
464 } else if (!strcmp(buf
, "threads")) {
465 /* this is the default */
467 error_report("invalid aio option");
473 if ((buf
= qemu_opt_get(opts
, "format")) != NULL
) {
474 if (is_help_option(buf
)) {
475 error_printf("Supported formats:");
476 bdrv_iterate_format(bdrv_format_print
, NULL
);
480 drv
= bdrv_find_whitelisted_format(buf
, ro
);
482 error_report("'%s' invalid format", buf
);
487 /* disk I/O throttling */
488 io_limits
.bps
[BLOCK_IO_LIMIT_TOTAL
] =
489 qemu_opt_get_number(opts
, "bps", 0);
490 io_limits
.bps
[BLOCK_IO_LIMIT_READ
] =
491 qemu_opt_get_number(opts
, "bps_rd", 0);
492 io_limits
.bps
[BLOCK_IO_LIMIT_WRITE
] =
493 qemu_opt_get_number(opts
, "bps_wr", 0);
494 io_limits
.iops
[BLOCK_IO_LIMIT_TOTAL
] =
495 qemu_opt_get_number(opts
, "iops", 0);
496 io_limits
.iops
[BLOCK_IO_LIMIT_READ
] =
497 qemu_opt_get_number(opts
, "iops_rd", 0);
498 io_limits
.iops
[BLOCK_IO_LIMIT_WRITE
] =
499 qemu_opt_get_number(opts
, "iops_wr", 0);
501 if (!do_check_io_limits(&io_limits
, &error
)) {
502 error_report("%s", error_get_pretty(error
));
507 if (qemu_opt_get(opts
, "boot") != NULL
) {
508 fprintf(stderr
, "qemu-kvm: boot=on|off is deprecated and will be "
509 "ignored. Future versions will reject this parameter. Please "
510 "update your scripts.\n");
513 on_write_error
= BLOCKDEV_ON_ERROR_ENOSPC
;
514 if ((buf
= qemu_opt_get(opts
, "werror")) != NULL
) {
515 if (type
!= IF_IDE
&& type
!= IF_SCSI
&& type
!= IF_VIRTIO
&& type
!= IF_NONE
) {
516 error_report("werror is not supported by this bus type");
520 on_write_error
= parse_block_error_action(buf
, 0);
521 if (on_write_error
< 0) {
526 on_read_error
= BLOCKDEV_ON_ERROR_REPORT
;
527 if ((buf
= qemu_opt_get(opts
, "rerror")) != NULL
) {
528 if (type
!= IF_IDE
&& type
!= IF_VIRTIO
&& type
!= IF_SCSI
&& type
!= IF_NONE
) {
529 error_report("rerror is not supported by this bus type");
533 on_read_error
= parse_block_error_action(buf
, 1);
534 if (on_read_error
< 0) {
539 if ((devaddr
= qemu_opt_get(opts
, "addr")) != NULL
) {
540 if (type
!= IF_VIRTIO
) {
541 error_report("addr is not supported by this bus type");
546 /* compute bus and unit according index */
549 if (bus_id
!= 0 || unit_id
!= -1) {
550 error_report("index cannot be used with bus and unit");
553 bus_id
= drive_index_to_bus_id(type
, index
);
554 unit_id
= drive_index_to_unit_id(type
, index
);
557 /* if user doesn't specify a unit_id,
558 * try to find the first free
563 while (drive_get(type
, bus_id
, unit_id
) != NULL
) {
565 if (max_devs
&& unit_id
>= max_devs
) {
574 if (max_devs
&& unit_id
>= max_devs
) {
575 error_report("unit %d too big (max is %d)",
576 unit_id
, max_devs
- 1);
581 * catch multiple definitions
584 if (drive_get(type
, bus_id
, unit_id
) != NULL
) {
585 error_report("drive with bus=%d, unit=%d (index=%d) exists",
586 bus_id
, unit_id
, index
);
592 dinfo
= g_malloc0(sizeof(*dinfo
));
593 if ((buf
= qemu_opts_id(opts
)) != NULL
) {
594 dinfo
->id
= g_strdup(buf
);
596 /* no id supplied -> create one */
597 dinfo
->id
= g_malloc0(32);
598 if (type
== IF_IDE
|| type
== IF_SCSI
)
599 mediastr
= (media
== MEDIA_CDROM
) ? "-cd" : "-hd";
601 snprintf(dinfo
->id
, 32, "%s%i%s%i",
602 if_name
[type
], bus_id
, mediastr
, unit_id
);
604 snprintf(dinfo
->id
, 32, "%s%s%i",
605 if_name
[type
], mediastr
, unit_id
);
607 dinfo
->bdrv
= bdrv_new(dinfo
->id
);
608 dinfo
->bdrv
->open_flags
= snapshot
? BDRV_O_SNAPSHOT
: 0;
609 dinfo
->bdrv
->read_only
= ro
;
610 dinfo
->devaddr
= devaddr
;
613 dinfo
->unit
= unit_id
;
615 dinfo
->heads
= heads
;
617 dinfo
->trans
= translation
;
618 dinfo
->opts
= all_opts
;
620 if (serial
!= NULL
) {
621 dinfo
->serial
= g_strdup(serial
);
623 QTAILQ_INSERT_TAIL(&drives
, dinfo
, next
);
625 bdrv_set_on_error(dinfo
->bdrv
, on_read_error
, on_write_error
);
627 /* disk I/O throttling */
628 bdrv_set_io_limits(dinfo
->bdrv
, &io_limits
);
635 dinfo
->media_cd
= media
== MEDIA_CDROM
;
644 /* add virtio block device */
646 devopts
= qemu_opts_create_nofail(qemu_find_opts("device"));
647 if (arch_type
== QEMU_ARCH_S390X
) {
648 qemu_opt_set(devopts
, "driver", "virtio-blk-s390");
650 qemu_opt_set(devopts
, "driver", "virtio-blk-pci");
652 qemu_opt_set(devopts
, "drive", dinfo
->id
);
654 qemu_opt_set(devopts
, "addr", devaddr
);
660 if (!file
|| !*file
) {
661 if (qdict_size(bs_opts
)) {
668 /* always use cache=unsafe with snapshot */
669 bdrv_flags
&= ~BDRV_O_CACHE_MASK
;
670 bdrv_flags
|= (BDRV_O_SNAPSHOT
|BDRV_O_CACHE_WB
|BDRV_O_NO_FLUSH
);
674 bdrv_flags
|= BDRV_O_COPY_ON_READ
;
677 if (runstate_check(RUN_STATE_INMIGRATE
)) {
678 bdrv_flags
|= BDRV_O_INCOMING
;
681 if (media
== MEDIA_CDROM
) {
682 /* CDROM is fine for any interface, don't check. */
684 } else if (ro
== 1) {
685 if (type
!= IF_SCSI
&& type
!= IF_VIRTIO
&& type
!= IF_FLOPPY
&&
686 type
!= IF_NONE
&& type
!= IF_PFLASH
) {
687 error_report("readonly not supported by this bus type");
692 bdrv_flags
|= ro
? 0 : BDRV_O_RDWR
;
694 if (ro
&& copy_on_read
) {
695 error_report("warning: disabling copy_on_read on readonly drive");
698 ret
= bdrv_open(dinfo
->bdrv
, file
, bs_opts
, bdrv_flags
, drv
);
702 if (ret
== -EMEDIUMTYPE
) {
703 error_report("could not open disk image %s: not in %s format",
704 file
?: dinfo
->id
, drv
->format_name
);
706 error_report("could not open disk image %s: %s",
707 file
?: dinfo
->id
, strerror(-ret
));
712 if (bdrv_key_required(dinfo
->bdrv
))
722 bdrv_delete(dinfo
->bdrv
);
724 QTAILQ_REMOVE(&drives
, dinfo
, next
);
729 void do_commit(Monitor
*mon
, const QDict
*qdict
)
731 const char *device
= qdict_get_str(qdict
, "device");
732 BlockDriverState
*bs
;
735 if (!strcmp(device
, "all")) {
736 ret
= bdrv_commit_all();
738 bs
= bdrv_find(device
);
740 monitor_printf(mon
, "Device '%s' not found\n", device
);
743 ret
= bdrv_commit(bs
);
746 monitor_printf(mon
, "'commit' error for '%s': %s\n", device
,
751 static void blockdev_do_action(int kind
, void *data
, Error
**errp
)
753 TransactionAction action
;
754 TransactionActionList list
;
758 list
.value
= &action
;
760 qmp_transaction(&list
, errp
);
763 void qmp_blockdev_snapshot_sync(const char *device
, const char *snapshot_file
,
764 bool has_format
, const char *format
,
765 bool has_mode
, enum NewImageMode mode
,
768 BlockdevSnapshot snapshot
= {
769 .device
= (char *) device
,
770 .snapshot_file
= (char *) snapshot_file
,
771 .has_format
= has_format
,
772 .format
= (char *) format
,
773 .has_mode
= has_mode
,
776 blockdev_do_action(TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC
,
781 /* New and old BlockDriverState structs for group snapshots */
783 typedef struct BlkTransactionState BlkTransactionState
;
785 /* Only prepare() may fail. In a single transaction, only one of commit() or
786 abort() will be called, clean() will always be called if it present. */
787 typedef struct BdrvActionOps
{
788 /* Size of state struct, in bytes. */
789 size_t instance_size
;
790 /* Prepare the work, must NOT be NULL. */
791 void (*prepare
)(BlkTransactionState
*common
, Error
**errp
);
792 /* Commit the changes, can be NULL. */
793 void (*commit
)(BlkTransactionState
*common
);
794 /* Abort the changes on fail, can be NULL. */
795 void (*abort
)(BlkTransactionState
*common
);
796 /* Clean up resource in the end, can be NULL. */
797 void (*clean
)(BlkTransactionState
*common
);
801 * This structure must be arranged as first member in child type, assuming
802 * that compiler will also arrange it to the same address with parent instance.
803 * Later it will be used in free().
805 struct BlkTransactionState
{
806 TransactionAction
*action
;
807 const BdrvActionOps
*ops
;
808 QSIMPLEQ_ENTRY(BlkTransactionState
) entry
;
811 /* external snapshot private data */
812 typedef struct ExternalSnapshotState
{
813 BlkTransactionState common
;
814 BlockDriverState
*old_bs
;
815 BlockDriverState
*new_bs
;
816 } ExternalSnapshotState
;
818 static void external_snapshot_prepare(BlkTransactionState
*common
,
823 Error
*local_err
= NULL
;
825 const char *new_image_file
;
826 const char *format
= "qcow2";
827 enum NewImageMode mode
= NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
828 ExternalSnapshotState
*state
=
829 DO_UPCAST(ExternalSnapshotState
, common
, common
);
830 TransactionAction
*action
= common
->action
;
833 g_assert(action
->kind
== TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC
);
835 device
= action
->blockdev_snapshot_sync
->device
;
836 new_image_file
= action
->blockdev_snapshot_sync
->snapshot_file
;
837 if (action
->blockdev_snapshot_sync
->has_format
) {
838 format
= action
->blockdev_snapshot_sync
->format
;
840 if (action
->blockdev_snapshot_sync
->has_mode
) {
841 mode
= action
->blockdev_snapshot_sync
->mode
;
844 /* start processing */
845 drv
= bdrv_find_format(format
);
847 error_set(errp
, QERR_INVALID_BLOCK_FORMAT
, format
);
851 state
->old_bs
= bdrv_find(device
);
852 if (!state
->old_bs
) {
853 error_set(errp
, QERR_DEVICE_NOT_FOUND
, device
);
857 if (!bdrv_is_inserted(state
->old_bs
)) {
858 error_set(errp
, QERR_DEVICE_HAS_NO_MEDIUM
, device
);
862 if (bdrv_in_use(state
->old_bs
)) {
863 error_set(errp
, QERR_DEVICE_IN_USE
, device
);
867 if (!bdrv_is_read_only(state
->old_bs
)) {
868 if (bdrv_flush(state
->old_bs
)) {
869 error_set(errp
, QERR_IO_ERROR
);
874 flags
= state
->old_bs
->open_flags
;
876 /* create new image w/backing file */
877 if (mode
!= NEW_IMAGE_MODE_EXISTING
) {
878 bdrv_img_create(new_image_file
, format
,
879 state
->old_bs
->filename
,
880 state
->old_bs
->drv
->format_name
,
881 NULL
, -1, flags
, &local_err
, false);
882 if (error_is_set(&local_err
)) {
883 error_propagate(errp
, local_err
);
888 /* We will manually add the backing_hd field to the bs later */
889 state
->new_bs
= bdrv_new("");
890 /* TODO Inherit bs->options or only take explicit options with an
891 * extended QMP command? */
892 ret
= bdrv_open(state
->new_bs
, new_image_file
, NULL
,
893 flags
| BDRV_O_NO_BACKING
, drv
);
895 error_setg_file_open(errp
, -ret
, new_image_file
);
899 static void external_snapshot_commit(BlkTransactionState
*common
)
901 ExternalSnapshotState
*state
=
902 DO_UPCAST(ExternalSnapshotState
, common
, common
);
904 /* This removes our old bs and adds the new bs */
905 bdrv_append(state
->new_bs
, state
->old_bs
);
906 /* We don't need (or want) to use the transactional
907 * bdrv_reopen_multiple() across all the entries at once, because we
908 * don't want to abort all of them if one of them fails the reopen */
909 bdrv_reopen(state
->new_bs
, state
->new_bs
->open_flags
& ~BDRV_O_RDWR
,
913 static void external_snapshot_abort(BlkTransactionState
*common
)
915 ExternalSnapshotState
*state
=
916 DO_UPCAST(ExternalSnapshotState
, common
, common
);
918 bdrv_delete(state
->new_bs
);
922 static const BdrvActionOps actions
[] = {
923 [TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC
] = {
924 .instance_size
= sizeof(ExternalSnapshotState
),
925 .prepare
= external_snapshot_prepare
,
926 .commit
= external_snapshot_commit
,
927 .abort
= external_snapshot_abort
,
932 * 'Atomic' group snapshots. The snapshots are taken as a set, and if any fail
933 * then we do not pivot any of the devices in the group, and abandon the
936 void qmp_transaction(TransactionActionList
*dev_list
, Error
**errp
)
938 TransactionActionList
*dev_entry
= dev_list
;
939 BlkTransactionState
*state
, *next
;
940 Error
*local_err
= NULL
;
942 QSIMPLEQ_HEAD(snap_bdrv_states
, BlkTransactionState
) snap_bdrv_states
;
943 QSIMPLEQ_INIT(&snap_bdrv_states
);
945 /* drain all i/o before any snapshots */
948 /* We don't do anything in this loop that commits us to the snapshot */
949 while (NULL
!= dev_entry
) {
950 TransactionAction
*dev_info
= NULL
;
951 const BdrvActionOps
*ops
;
953 dev_info
= dev_entry
->value
;
954 dev_entry
= dev_entry
->next
;
956 assert(dev_info
->kind
< ARRAY_SIZE(actions
));
958 ops
= &actions
[dev_info
->kind
];
959 state
= g_malloc0(ops
->instance_size
);
961 state
->action
= dev_info
;
962 QSIMPLEQ_INSERT_TAIL(&snap_bdrv_states
, state
, entry
);
964 state
->ops
->prepare(state
, &local_err
);
965 if (error_is_set(&local_err
)) {
966 error_propagate(errp
, local_err
);
967 goto delete_and_fail
;
971 QSIMPLEQ_FOREACH(state
, &snap_bdrv_states
, entry
) {
972 if (state
->ops
->commit
) {
973 state
->ops
->commit(state
);
982 * failure, and it is all-or-none; abandon each new bs, and keep using
983 * the original bs for all images
985 QSIMPLEQ_FOREACH(state
, &snap_bdrv_states
, entry
) {
986 if (state
->ops
->abort
) {
987 state
->ops
->abort(state
);
991 QSIMPLEQ_FOREACH_SAFE(state
, &snap_bdrv_states
, entry
, next
) {
992 if (state
->ops
->clean
) {
993 state
->ops
->clean(state
);
1000 static void eject_device(BlockDriverState
*bs
, int force
, Error
**errp
)
1002 if (bdrv_in_use(bs
)) {
1003 error_set(errp
, QERR_DEVICE_IN_USE
, bdrv_get_device_name(bs
));
1006 if (!bdrv_dev_has_removable_media(bs
)) {
1007 error_set(errp
, QERR_DEVICE_NOT_REMOVABLE
, bdrv_get_device_name(bs
));
1011 if (bdrv_dev_is_medium_locked(bs
) && !bdrv_dev_is_tray_open(bs
)) {
1012 bdrv_dev_eject_request(bs
, force
);
1014 error_set(errp
, QERR_DEVICE_LOCKED
, bdrv_get_device_name(bs
));
1022 void qmp_eject(const char *device
, bool has_force
, bool force
, Error
**errp
)
1024 BlockDriverState
*bs
;
1026 bs
= bdrv_find(device
);
1028 error_set(errp
, QERR_DEVICE_NOT_FOUND
, device
);
1032 eject_device(bs
, force
, errp
);
1035 void qmp_block_passwd(const char *device
, const char *password
, Error
**errp
)
1037 BlockDriverState
*bs
;
1040 bs
= bdrv_find(device
);
1042 error_set(errp
, QERR_DEVICE_NOT_FOUND
, device
);
1046 err
= bdrv_set_key(bs
, password
);
1047 if (err
== -EINVAL
) {
1048 error_set(errp
, QERR_DEVICE_NOT_ENCRYPTED
, bdrv_get_device_name(bs
));
1050 } else if (err
< 0) {
1051 error_set(errp
, QERR_INVALID_PASSWORD
);
1056 static void qmp_bdrv_open_encrypted(BlockDriverState
*bs
, const char *filename
,
1057 int bdrv_flags
, BlockDriver
*drv
,
1058 const char *password
, Error
**errp
)
1062 ret
= bdrv_open(bs
, filename
, NULL
, bdrv_flags
, drv
);
1064 error_setg_file_open(errp
, -ret
, filename
);
1068 if (bdrv_key_required(bs
)) {
1070 if (bdrv_set_key(bs
, password
) < 0) {
1071 error_set(errp
, QERR_INVALID_PASSWORD
);
1074 error_set(errp
, QERR_DEVICE_ENCRYPTED
, bdrv_get_device_name(bs
),
1075 bdrv_get_encrypted_filename(bs
));
1077 } else if (password
) {
1078 error_set(errp
, QERR_DEVICE_NOT_ENCRYPTED
, bdrv_get_device_name(bs
));
1082 void qmp_change_blockdev(const char *device
, const char *filename
,
1083 bool has_format
, const char *format
, Error
**errp
)
1085 BlockDriverState
*bs
;
1086 BlockDriver
*drv
= NULL
;
1090 bs
= bdrv_find(device
);
1092 error_set(errp
, QERR_DEVICE_NOT_FOUND
, device
);
1097 drv
= bdrv_find_whitelisted_format(format
, bs
->read_only
);
1099 error_set(errp
, QERR_INVALID_BLOCK_FORMAT
, format
);
1104 eject_device(bs
, 0, &err
);
1105 if (error_is_set(&err
)) {
1106 error_propagate(errp
, err
);
1110 bdrv_flags
= bdrv_is_read_only(bs
) ? 0 : BDRV_O_RDWR
;
1111 bdrv_flags
|= bdrv_is_snapshot(bs
) ? BDRV_O_SNAPSHOT
: 0;
1113 qmp_bdrv_open_encrypted(bs
, filename
, bdrv_flags
, drv
, NULL
, errp
);
1116 /* throttling disk I/O limits */
1117 void qmp_block_set_io_throttle(const char *device
, int64_t bps
, int64_t bps_rd
,
1118 int64_t bps_wr
, int64_t iops
, int64_t iops_rd
,
1119 int64_t iops_wr
, Error
**errp
)
1121 BlockIOLimit io_limits
;
1122 BlockDriverState
*bs
;
1124 bs
= bdrv_find(device
);
1126 error_set(errp
, QERR_DEVICE_NOT_FOUND
, device
);
1130 io_limits
.bps
[BLOCK_IO_LIMIT_TOTAL
] = bps
;
1131 io_limits
.bps
[BLOCK_IO_LIMIT_READ
] = bps_rd
;
1132 io_limits
.bps
[BLOCK_IO_LIMIT_WRITE
] = bps_wr
;
1133 io_limits
.iops
[BLOCK_IO_LIMIT_TOTAL
]= iops
;
1134 io_limits
.iops
[BLOCK_IO_LIMIT_READ
] = iops_rd
;
1135 io_limits
.iops
[BLOCK_IO_LIMIT_WRITE
]= iops_wr
;
1137 if (!do_check_io_limits(&io_limits
, errp
)) {
1141 bs
->io_limits
= io_limits
;
1143 if (!bs
->io_limits_enabled
&& bdrv_io_limits_enabled(bs
)) {
1144 bdrv_io_limits_enable(bs
);
1145 } else if (bs
->io_limits_enabled
&& !bdrv_io_limits_enabled(bs
)) {
1146 bdrv_io_limits_disable(bs
);
1148 if (bs
->block_timer
) {
1149 qemu_mod_timer(bs
->block_timer
, qemu_get_clock_ns(vm_clock
));
1154 int do_drive_del(Monitor
*mon
, const QDict
*qdict
, QObject
**ret_data
)
1156 const char *id
= qdict_get_str(qdict
, "id");
1157 BlockDriverState
*bs
;
1161 qerror_report(QERR_DEVICE_NOT_FOUND
, id
);
1164 if (bdrv_in_use(bs
)) {
1165 qerror_report(QERR_DEVICE_IN_USE
, id
);
1169 /* quiesce block driver; prevent further io */
1174 /* if we have a device attached to this BlockDriverState
1175 * then we need to make the drive anonymous until the device
1176 * can be removed. If this is a drive with no device backing
1177 * then we can just get rid of the block driver state right here.
1179 if (bdrv_get_attached_dev(bs
)) {
1182 /* Further I/O must not pause the guest */
1183 bdrv_set_on_error(bs
, BLOCKDEV_ON_ERROR_REPORT
,
1184 BLOCKDEV_ON_ERROR_REPORT
);
1186 drive_uninit(drive_get_by_blockdev(bs
));
1192 void qmp_block_resize(const char *device
, int64_t size
, Error
**errp
)
1194 BlockDriverState
*bs
;
1197 bs
= bdrv_find(device
);
1199 error_set(errp
, QERR_DEVICE_NOT_FOUND
, device
);
1204 error_set(errp
, QERR_INVALID_PARAMETER_VALUE
, "size", "a >0 size");
1208 /* complete all in-flight operations before resizing the device */
1211 ret
= bdrv_truncate(bs
, size
);
1216 error_set(errp
, QERR_DEVICE_HAS_NO_MEDIUM
, device
);
1219 error_set(errp
, QERR_UNSUPPORTED
);
1222 error_set(errp
, QERR_DEVICE_IS_READ_ONLY
, device
);
1225 error_set(errp
, QERR_DEVICE_IN_USE
, device
);
1228 error_setg_errno(errp
, -ret
, "Could not resize");
1233 static void block_job_cb(void *opaque
, int ret
)
1235 BlockDriverState
*bs
= opaque
;
1238 trace_block_job_cb(bs
, bs
->job
, ret
);
1241 obj
= qobject_from_block_job(bs
->job
);
1243 QDict
*dict
= qobject_to_qdict(obj
);
1244 qdict_put(dict
, "error", qstring_from_str(strerror(-ret
)));
1247 if (block_job_is_cancelled(bs
->job
)) {
1248 monitor_protocol_event(QEVENT_BLOCK_JOB_CANCELLED
, obj
);
1250 monitor_protocol_event(QEVENT_BLOCK_JOB_COMPLETED
, obj
);
1252 qobject_decref(obj
);
1254 drive_put_ref_bh_schedule(drive_get_by_blockdev(bs
));
1257 void qmp_block_stream(const char *device
, bool has_base
,
1258 const char *base
, bool has_speed
, int64_t speed
,
1259 bool has_on_error
, BlockdevOnError on_error
,
1262 BlockDriverState
*bs
;
1263 BlockDriverState
*base_bs
= NULL
;
1264 Error
*local_err
= NULL
;
1266 if (!has_on_error
) {
1267 on_error
= BLOCKDEV_ON_ERROR_REPORT
;
1270 bs
= bdrv_find(device
);
1272 error_set(errp
, QERR_DEVICE_NOT_FOUND
, device
);
1277 base_bs
= bdrv_find_backing_image(bs
, base
);
1278 if (base_bs
== NULL
) {
1279 error_set(errp
, QERR_BASE_NOT_FOUND
, base
);
1284 stream_start(bs
, base_bs
, base
, has_speed
? speed
: 0,
1285 on_error
, block_job_cb
, bs
, &local_err
);
1286 if (error_is_set(&local_err
)) {
1287 error_propagate(errp
, local_err
);
1291 /* Grab a reference so hotplug does not delete the BlockDriverState from
1294 drive_get_ref(drive_get_by_blockdev(bs
));
1296 trace_qmp_block_stream(bs
, bs
->job
);
1299 void qmp_block_commit(const char *device
,
1300 bool has_base
, const char *base
, const char *top
,
1301 bool has_speed
, int64_t speed
,
1304 BlockDriverState
*bs
;
1305 BlockDriverState
*base_bs
, *top_bs
;
1306 Error
*local_err
= NULL
;
1307 /* This will be part of the QMP command, if/when the
1308 * BlockdevOnError change for blkmirror makes it in
1310 BlockdevOnError on_error
= BLOCKDEV_ON_ERROR_REPORT
;
1312 /* drain all i/o before commits */
1315 bs
= bdrv_find(device
);
1317 error_set(errp
, QERR_DEVICE_NOT_FOUND
, device
);
1321 /* default top_bs is the active layer */
1325 if (strcmp(bs
->filename
, top
) != 0) {
1326 top_bs
= bdrv_find_backing_image(bs
, top
);
1330 if (top_bs
== NULL
) {
1331 error_setg(errp
, "Top image file %s not found", top
? top
: "NULL");
1335 if (has_base
&& base
) {
1336 base_bs
= bdrv_find_backing_image(top_bs
, base
);
1338 base_bs
= bdrv_find_base(top_bs
);
1341 if (base_bs
== NULL
) {
1342 error_set(errp
, QERR_BASE_NOT_FOUND
, base
? base
: "NULL");
1346 commit_start(bs
, base_bs
, top_bs
, speed
, on_error
, block_job_cb
, bs
,
1348 if (local_err
!= NULL
) {
1349 error_propagate(errp
, local_err
);
1352 /* Grab a reference so hotplug does not delete the BlockDriverState from
1355 drive_get_ref(drive_get_by_blockdev(bs
));
1358 void qmp_drive_backup(const char *device
, const char *target
,
1359 bool has_format
, const char *format
,
1360 bool has_mode
, enum NewImageMode mode
,
1361 bool has_speed
, int64_t speed
,
1362 bool has_on_source_error
, BlockdevOnError on_source_error
,
1363 bool has_on_target_error
, BlockdevOnError on_target_error
,
1366 BlockDriverState
*bs
;
1367 BlockDriverState
*target_bs
;
1368 BlockDriver
*drv
= NULL
;
1369 Error
*local_err
= NULL
;
1377 if (!has_on_source_error
) {
1378 on_source_error
= BLOCKDEV_ON_ERROR_REPORT
;
1380 if (!has_on_target_error
) {
1381 on_target_error
= BLOCKDEV_ON_ERROR_REPORT
;
1384 mode
= NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
1387 bs
= bdrv_find(device
);
1389 error_set(errp
, QERR_DEVICE_NOT_FOUND
, device
);
1393 if (!bdrv_is_inserted(bs
)) {
1394 error_set(errp
, QERR_DEVICE_HAS_NO_MEDIUM
, device
);
1399 format
= mode
== NEW_IMAGE_MODE_EXISTING
? NULL
: bs
->drv
->format_name
;
1402 drv
= bdrv_find_format(format
);
1404 error_set(errp
, QERR_INVALID_BLOCK_FORMAT
, format
);
1409 if (bdrv_in_use(bs
)) {
1410 error_set(errp
, QERR_DEVICE_IN_USE
, device
);
1414 flags
= bs
->open_flags
| BDRV_O_RDWR
;
1416 size
= bdrv_getlength(bs
);
1418 error_setg_errno(errp
, -size
, "bdrv_getlength failed");
1422 if (mode
!= NEW_IMAGE_MODE_EXISTING
) {
1423 assert(format
&& drv
);
1424 bdrv_img_create(target
, format
,
1425 NULL
, NULL
, NULL
, size
, flags
, &local_err
, false);
1428 if (error_is_set(&local_err
)) {
1429 error_propagate(errp
, local_err
);
1433 target_bs
= bdrv_new("");
1434 ret
= bdrv_open(target_bs
, target
, NULL
, flags
, drv
);
1436 bdrv_delete(target_bs
);
1437 error_setg_file_open(errp
, -ret
, target
);
1441 backup_start(bs
, target_bs
, speed
, on_source_error
, on_target_error
,
1442 block_job_cb
, bs
, &local_err
);
1443 if (local_err
!= NULL
) {
1444 bdrv_delete(target_bs
);
1445 error_propagate(errp
, local_err
);
1449 /* Grab a reference so hotplug does not delete the BlockDriverState from
1452 drive_get_ref(drive_get_by_blockdev(bs
));
1455 #define DEFAULT_MIRROR_BUF_SIZE (10 << 20)
1457 void qmp_drive_mirror(const char *device
, const char *target
,
1458 bool has_format
, const char *format
,
1459 enum MirrorSyncMode sync
,
1460 bool has_mode
, enum NewImageMode mode
,
1461 bool has_speed
, int64_t speed
,
1462 bool has_granularity
, uint32_t granularity
,
1463 bool has_buf_size
, int64_t buf_size
,
1464 bool has_on_source_error
, BlockdevOnError on_source_error
,
1465 bool has_on_target_error
, BlockdevOnError on_target_error
,
1468 BlockDriverState
*bs
;
1469 BlockDriverState
*source
, *target_bs
;
1470 BlockDriver
*drv
= NULL
;
1471 Error
*local_err
= NULL
;
1479 if (!has_on_source_error
) {
1480 on_source_error
= BLOCKDEV_ON_ERROR_REPORT
;
1482 if (!has_on_target_error
) {
1483 on_target_error
= BLOCKDEV_ON_ERROR_REPORT
;
1486 mode
= NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
1488 if (!has_granularity
) {
1491 if (!has_buf_size
) {
1492 buf_size
= DEFAULT_MIRROR_BUF_SIZE
;
1495 if (granularity
!= 0 && (granularity
< 512 || granularity
> 1048576 * 64)) {
1496 error_set(errp
, QERR_INVALID_PARAMETER
, device
);
1499 if (granularity
& (granularity
- 1)) {
1500 error_set(errp
, QERR_INVALID_PARAMETER
, device
);
1504 bs
= bdrv_find(device
);
1506 error_set(errp
, QERR_DEVICE_NOT_FOUND
, device
);
1510 if (!bdrv_is_inserted(bs
)) {
1511 error_set(errp
, QERR_DEVICE_HAS_NO_MEDIUM
, device
);
1516 format
= mode
== NEW_IMAGE_MODE_EXISTING
? NULL
: bs
->drv
->format_name
;
1519 drv
= bdrv_find_format(format
);
1521 error_set(errp
, QERR_INVALID_BLOCK_FORMAT
, format
);
1526 if (bdrv_in_use(bs
)) {
1527 error_set(errp
, QERR_DEVICE_IN_USE
, device
);
1531 flags
= bs
->open_flags
| BDRV_O_RDWR
;
1532 source
= bs
->backing_hd
;
1533 if (!source
&& sync
== MIRROR_SYNC_MODE_TOP
) {
1534 sync
= MIRROR_SYNC_MODE_FULL
;
1537 size
= bdrv_getlength(bs
);
1539 error_setg_errno(errp
, -size
, "bdrv_getlength failed");
1543 if (sync
== MIRROR_SYNC_MODE_FULL
&& mode
!= NEW_IMAGE_MODE_EXISTING
) {
1544 /* create new image w/o backing file */
1545 assert(format
&& drv
);
1546 bdrv_img_create(target
, format
,
1547 NULL
, NULL
, NULL
, size
, flags
, &local_err
, false);
1550 case NEW_IMAGE_MODE_EXISTING
:
1553 case NEW_IMAGE_MODE_ABSOLUTE_PATHS
:
1554 /* create new image with backing file */
1555 bdrv_img_create(target
, format
,
1557 source
->drv
->format_name
,
1558 NULL
, size
, flags
, &local_err
, false);
1565 if (error_is_set(&local_err
)) {
1566 error_propagate(errp
, local_err
);
1570 /* Mirroring takes care of copy-on-write using the source's backing
1573 target_bs
= bdrv_new("");
1574 ret
= bdrv_open(target_bs
, target
, NULL
, flags
| BDRV_O_NO_BACKING
, drv
);
1576 bdrv_delete(target_bs
);
1577 error_setg_file_open(errp
, -ret
, target
);
1581 mirror_start(bs
, target_bs
, speed
, granularity
, buf_size
, sync
,
1582 on_source_error
, on_target_error
,
1583 block_job_cb
, bs
, &local_err
);
1584 if (local_err
!= NULL
) {
1585 bdrv_delete(target_bs
);
1586 error_propagate(errp
, local_err
);
1590 /* Grab a reference so hotplug does not delete the BlockDriverState from
1593 drive_get_ref(drive_get_by_blockdev(bs
));
1596 static BlockJob
*find_block_job(const char *device
)
1598 BlockDriverState
*bs
;
1600 bs
= bdrv_find(device
);
1601 if (!bs
|| !bs
->job
) {
1607 void qmp_block_job_set_speed(const char *device
, int64_t speed
, Error
**errp
)
1609 BlockJob
*job
= find_block_job(device
);
1612 error_set(errp
, QERR_BLOCK_JOB_NOT_ACTIVE
, device
);
1616 block_job_set_speed(job
, speed
, errp
);
1619 void qmp_block_job_cancel(const char *device
,
1620 bool has_force
, bool force
, Error
**errp
)
1622 BlockJob
*job
= find_block_job(device
);
1629 error_set(errp
, QERR_BLOCK_JOB_NOT_ACTIVE
, device
);
1632 if (job
->paused
&& !force
) {
1633 error_set(errp
, QERR_BLOCK_JOB_PAUSED
, device
);
1637 trace_qmp_block_job_cancel(job
);
1638 block_job_cancel(job
);
1641 void qmp_block_job_pause(const char *device
, Error
**errp
)
1643 BlockJob
*job
= find_block_job(device
);
1646 error_set(errp
, QERR_BLOCK_JOB_NOT_ACTIVE
, device
);
1650 trace_qmp_block_job_pause(job
);
1651 block_job_pause(job
);
1654 void qmp_block_job_resume(const char *device
, Error
**errp
)
1656 BlockJob
*job
= find_block_job(device
);
1659 error_set(errp
, QERR_BLOCK_JOB_NOT_ACTIVE
, device
);
1663 trace_qmp_block_job_resume(job
);
1664 block_job_resume(job
);
1667 void qmp_block_job_complete(const char *device
, Error
**errp
)
1669 BlockJob
*job
= find_block_job(device
);
1672 error_set(errp
, QERR_BLOCK_JOB_NOT_ACTIVE
, device
);
1676 trace_qmp_block_job_complete(job
);
1677 block_job_complete(job
, errp
);
1680 static void do_qmp_query_block_jobs_one(void *opaque
, BlockDriverState
*bs
)
1682 BlockJobInfoList
**prev
= opaque
;
1683 BlockJob
*job
= bs
->job
;
1686 BlockJobInfoList
*elem
= g_new0(BlockJobInfoList
, 1);
1687 elem
->value
= block_job_query(bs
->job
);
1688 (*prev
)->next
= elem
;
1693 BlockJobInfoList
*qmp_query_block_jobs(Error
**errp
)
1695 /* Dummy is a fake list element for holding the head pointer */
1696 BlockJobInfoList dummy
= {};
1697 BlockJobInfoList
*prev
= &dummy
;
1698 bdrv_iterate(do_qmp_query_block_jobs_one
, &prev
);
1702 QemuOptsList qemu_common_drive_opts
= {
1704 .head
= QTAILQ_HEAD_INITIALIZER(qemu_common_drive_opts
.head
),
1708 .type
= QEMU_OPT_NUMBER
,
1709 .help
= "bus number",
1712 .type
= QEMU_OPT_NUMBER
,
1713 .help
= "unit number (i.e. lun for scsi)",
1716 .type
= QEMU_OPT_STRING
,
1717 .help
= "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)",
1720 .type
= QEMU_OPT_NUMBER
,
1721 .help
= "index number",
1724 .type
= QEMU_OPT_NUMBER
,
1725 .help
= "number of cylinders (ide disk geometry)",
1728 .type
= QEMU_OPT_NUMBER
,
1729 .help
= "number of heads (ide disk geometry)",
1732 .type
= QEMU_OPT_NUMBER
,
1733 .help
= "number of sectors (ide disk geometry)",
1736 .type
= QEMU_OPT_STRING
,
1737 .help
= "chs translation (auto, lba. none)",
1740 .type
= QEMU_OPT_STRING
,
1741 .help
= "media type (disk, cdrom)",
1744 .type
= QEMU_OPT_BOOL
,
1745 .help
= "enable/disable snapshot mode",
1748 .type
= QEMU_OPT_STRING
,
1749 .help
= "disk image",
1752 .type
= QEMU_OPT_STRING
,
1753 .help
= "discard operation (ignore/off, unmap/on)",
1756 .type
= QEMU_OPT_STRING
,
1757 .help
= "host cache usage (none, writeback, writethrough, "
1758 "directsync, unsafe)",
1761 .type
= QEMU_OPT_STRING
,
1762 .help
= "host AIO implementation (threads, native)",
1765 .type
= QEMU_OPT_STRING
,
1766 .help
= "disk format (raw, qcow2, ...)",
1769 .type
= QEMU_OPT_STRING
,
1770 .help
= "disk serial number",
1773 .type
= QEMU_OPT_STRING
,
1774 .help
= "read error action",
1777 .type
= QEMU_OPT_STRING
,
1778 .help
= "write error action",
1781 .type
= QEMU_OPT_STRING
,
1782 .help
= "pci address (virtio only)",
1785 .type
= QEMU_OPT_BOOL
,
1786 .help
= "open drive file as read-only",
1789 .type
= QEMU_OPT_NUMBER
,
1790 .help
= "limit total I/O operations per second",
1793 .type
= QEMU_OPT_NUMBER
,
1794 .help
= "limit read operations per second",
1797 .type
= QEMU_OPT_NUMBER
,
1798 .help
= "limit write operations per second",
1801 .type
= QEMU_OPT_NUMBER
,
1802 .help
= "limit total bytes per second",
1805 .type
= QEMU_OPT_NUMBER
,
1806 .help
= "limit read bytes per second",
1809 .type
= QEMU_OPT_NUMBER
,
1810 .help
= "limit write bytes per second",
1812 .name
= "copy-on-read",
1813 .type
= QEMU_OPT_BOOL
,
1814 .help
= "copy read data from backing file into image file",
1817 .type
= QEMU_OPT_BOOL
,
1818 .help
= "(deprecated, ignored)",
1820 { /* end of list */ }
1824 QemuOptsList qemu_drive_opts
= {
1826 .head
= QTAILQ_HEAD_INITIALIZER(qemu_drive_opts
.head
),
1829 * no elements => accept any params
1830 * validation will happen later
1832 { /* end of list */ }