[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 06/13] block: Support driver specific options in dri
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 06/13] block: Support driver specific options in drive_init() |
Date: |
Tue, 12 Mar 2013 15:41:12 +0100 |
Any non-default -drive options are now passed down to the block drivers.
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: Stefan Hajnoczi <address@hidden>
---
blockdev.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 59 insertions(+), 10 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index d679174..d0fd1e2 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -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,36 @@ DriveInfo *drive_init(QemuOpts *opts, BlockInterfaceType
block_default_type)
bool copy_on_read;
int ret;
Error *error = NULL;
+ QemuOpts *opts;
+ QDict *bs_opts;
+ const char *id;
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. */
+ id = qemu_opts_id(all_opts);
+ opts = qemu_opts_create(&qemu_common_drive_opts, id, 1, &error);
+ if (error_is_set(&error)) {
+ qerror_report_err(error);
+ error_free(error);
+ return NULL;
+ }
+
+ 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;
+ }
+
+ if (id) {
+ qdict_del(bs_opts, "id");
+ }
+
/* extract parameters */
bus_id = qemu_opt_get_number(opts, "bus", 0);
unit_id = qemu_opt_get_number(opts, "unit", -1);
@@ -564,7 +591,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);
@@ -587,17 +614,20 @@ DriveInfo *drive_init(QemuOpts *opts, BlockInterfaceType
block_default_type)
case IF_MTD:
break;
case IF_VIRTIO:
+ {
/* add virtio block device */
- opts = qemu_opts_create_nofail(qemu_find_opts("device"));
+ QemuOpts *devopts;
+ devopts = qemu_opts_create_nofail(qemu_find_opts("device"));
if (arch_type == QEMU_ARCH_S390X) {
- qemu_opt_set(opts, "driver", "virtio-blk-s390");
+ qemu_opt_set(devopts, "driver", "virtio-blk-s390");
} else {
- qemu_opt_set(opts, "driver", "virtio-blk-pci");
+ qemu_opt_set(devopts, "driver", "virtio-blk-pci");
}
- qemu_opt_set(opts, "drive", dinfo->id);
+ qemu_opt_set(devopts, "drive", dinfo->id);
if (devaddr)
- qemu_opt_set(opts, "addr", devaddr);
+ qemu_opt_set(devopts, "addr", devaddr);
break;
+ }
default:
abort();
}
@@ -635,7 +665,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 +681,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 +1498,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 +1619,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 */ }
+ },
+};
--
1.8.1.4
- [Qemu-devel] [PULL 00/13] Block patches, Kevin Wolf, 2013/03/12
- [Qemu-devel] [PATCH 04/13] block: Add options QDict to bdrv_open_common(), Kevin Wolf, 2013/03/12
- [Qemu-devel] [PATCH 01/13] block: Add options QDict to .bdrv_open(), Kevin Wolf, 2013/03/12
- [Qemu-devel] [PATCH 02/13] block: Add options QDict to bdrv_open() prototype, Kevin Wolf, 2013/03/12
- [Qemu-devel] [PATCH 08/13] qcow2: flush refcount cache correctly in alloc_refcount_block(), Kevin Wolf, 2013/03/12
- [Qemu-devel] [PATCH 06/13] block: Support driver specific options in drive_init(),
Kevin Wolf <=
- [Qemu-devel] [PATCH 03/13] Add qdict_clone_shallow(), Kevin Wolf, 2013/03/12
- [Qemu-devel] [PATCH 05/13] qemu-option: Add qemu_opts_absorb_qdict(), Kevin Wolf, 2013/03/12
- [Qemu-devel] [PATCH 09/13] qcow2: flush refcount cache correctly in qcow2_write_snapshots(), Kevin Wolf, 2013/03/12
- [Qemu-devel] [PATCH 11/13] qcow2: flush in qcow2_update_snapshot_refcount(), Kevin Wolf, 2013/03/12
- [Qemu-devel] [PATCH 10/13] qcow2: set L2 cache dependency in qcow2_alloc_bytes(), Kevin Wolf, 2013/03/12
- [Qemu-devel] [PATCH 07/13] qcow2: Allow lazy refcounts to be enabled on the command line, Kevin Wolf, 2013/03/12
- [Qemu-devel] [PATCH 12/13] qcow2: drop flush in update_cluster_refcount(), Kevin Wolf, 2013/03/12