@@ -22,6 +22,7 @@
#include "sysemu/arch_init.h"
static QTAILQ_HEAD(drivelist, DriveInfo) drives = QTAILQ_HEAD_INITIALIZER(drives);
+extern QemuOptsList qemu_common_drive_opts;
static const char *const if_name[IF_COUNT] = {
[IF_NONE] = "none",
@@ -287,7 +288,7 @@ static bool do_check_io_limits(BlockIOLimit *io_limits, Error **errp)
return true;
}
-DriveInfo *drive_init(QemuOpts *opts, BlockInterfaceType block_default_type)
+DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
{
const char *buf;
const char *file = NULL;
@@ -310,10 +311,25 @@ DriveInfo *drive_init(QemuOpts *opts, BlockInterfaceType block_default_type)
bool copy_on_read;
int ret;
Error *error = NULL;
+ QemuOpts *opts;
+ QDict *bs_opts;
translation = BIOS_ATA_TRANSLATION_AUTO;
media = MEDIA_DISK;
+ /* Check common options by copying from all_opts to opts, all other options
+ * are stored in bs_opts. */
+ opts = qemu_opts_create_nofail(&qemu_common_drive_opts);
+
+ bs_opts = qdict_new();
+ qemu_opts_to_qdict(all_opts, bs_opts);
+ qemu_opts_absorb_qdict(opts, bs_opts, &error);
+ if (error_is_set(&error)) {
+ qerror_report_err(error);
+ error_free(error);
+ return NULL;
+ }
+
/* extract parameters */
bus_id = qemu_opt_get_number(opts, "bus", 0);
unit_id = qemu_opt_get_number(opts, "unit", -1);
@@ -564,7 +580,7 @@ DriveInfo *drive_init(QemuOpts *opts, BlockInterfaceType block_default_type)
dinfo->heads = heads;
dinfo->secs = secs;
dinfo->trans = translation;
- dinfo->opts = opts;
+ dinfo->opts = all_opts;
dinfo->refcount = 1;
dinfo->serial = serial;
QTAILQ_INSERT_TAIL(&drives, dinfo, next);
@@ -635,7 +651,9 @@ DriveInfo *drive_init(QemuOpts *opts, BlockInterfaceType block_default_type)
error_report("warning: disabling copy_on_read on readonly drive");
}
- ret = bdrv_open(dinfo->bdrv, file, NULL, bdrv_flags, drv);
+ ret = bdrv_open(dinfo->bdrv, file, bs_opts, bdrv_flags, drv);
+ bs_opts = NULL;
+
if (ret < 0) {
if (ret == -EMEDIUMTYPE) {
error_report("could not open disk image %s: not in %s format",
@@ -649,9 +667,14 @@ DriveInfo *drive_init(QemuOpts *opts, BlockInterfaceType block_default_type)
if (bdrv_key_required(dinfo->bdrv))
autostart = 0;
+
+ qemu_opts_del(opts);
+
return dinfo;
err:
+ qemu_opts_del(opts);
+ QDECREF(bs_opts);
bdrv_delete(dinfo->bdrv);
g_free(dinfo->id);
QTAILQ_REMOVE(&drives, dinfo, next);
@@ -1461,9 +1484,9 @@ BlockJobInfoList *qmp_query_block_jobs(Error **errp)
return dummy.next;
}
-QemuOptsList qemu_drive_opts = {
+QemuOptsList qemu_common_drive_opts = {
.name = "drive",
- .head = QTAILQ_HEAD_INITIALIZER(qemu_drive_opts.head),
+ .head = QTAILQ_HEAD_INITIALIZER(qemu_common_drive_opts.head),
.desc = {
{
.name = "bus",
@@ -1582,3 +1605,15 @@ QemuOptsList qemu_drive_opts = {
{ /* end of list */ }
},
};
+
+QemuOptsList qemu_drive_opts = {
+ .name = "drive",
+ .head = QTAILQ_HEAD_INITIALIZER(qemu_drive_opts.head),
+ .desc = {
+ /*
+ * no elements => accept any params
+ * validation will happen later
+ */
+ { /* end of list */ }
+ },
+};
Any non-default -drive options are now passed down to the block drivers. Signed-off-by: Kevin Wolf <kwolf@redhat.com> --- blockdev.c | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-)