[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 11/17] blockdev: Move bus/unit/index processing to d
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 11/17] blockdev: Move bus/unit/index processing to drive_init |
Date: |
Fri, 20 Sep 2013 13:54:24 +0200 |
This requires moving the automatic ID generation at the same time, so
let's do that as well.
Signed-off-by: Kevin Wolf <address@hidden>
---
blockdev.c | 157 ++++++++++++++++++++++++++++---------------------------------
1 file changed, 73 insertions(+), 84 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index 33383be..26127b3 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -312,10 +312,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
const char *buf;
const char *file = NULL;
const char *serial;
- const char *mediastr = "";
- int bus_id, unit_id;
- int max_devs;
- int index;
int ro = 0;
int bdrv_flags = 0;
int on_read_error, on_write_error;
@@ -355,10 +351,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
has_driver_specific_opts = !!qdict_size(bs_opts);
/* extract parameters */
- bus_id = qemu_opt_get_number(opts, "bus", 0);
- unit_id = qemu_opt_get_number(opts, "unit", -1);
- index = qemu_opt_get_number(opts, "index", -1);
-
snapshot = qemu_opt_get_bool(opts, "snapshot", 0);
ro = qemu_opt_get_bool(opts, "read-only", 0);
copy_on_read = qemu_opt_get_bool(opts, "copy-on-read", false);
@@ -366,8 +358,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
file = qemu_opt_get(opts, "file");
serial = qemu_opt_get(opts, "serial");
- max_devs = if_max_devs[type];
-
if ((buf = qemu_opt_get(opts, "discard")) != NULL) {
if (bdrv_parse_discard_flags(buf, &bdrv_flags) != 0) {
error_report("invalid discard option");
@@ -486,66 +476,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
}
}
- /* compute bus and unit according index */
-
- if (index != -1) {
- if (bus_id != 0 || unit_id != -1) {
- error_report("index cannot be used with bus and unit");
- return NULL;
- }
- bus_id = drive_index_to_bus_id(type, index);
- unit_id = drive_index_to_unit_id(type, index);
- }
-
- /* if user doesn't specify a unit_id,
- * try to find the first free
- */
-
- if (unit_id == -1) {
- unit_id = 0;
- while (drive_get(type, bus_id, unit_id) != NULL) {
- unit_id++;
- if (max_devs && unit_id >= max_devs) {
- unit_id -= max_devs;
- bus_id++;
- }
- }
- }
-
- /* check unit id */
-
- if (max_devs && unit_id >= max_devs) {
- error_report("unit %d too big (max is %d)",
- unit_id, max_devs - 1);
- return NULL;
- }
-
- /*
- * catch multiple definitions
- */
-
- if (drive_get(type, bus_id, unit_id) != NULL) {
- error_report("drive with bus=%d, unit=%d (index=%d) exists",
- bus_id, unit_id, index);
- return NULL;
- }
-
- /* no id supplied -> create one */
- if (qemu_opts_id(opts) == NULL) {
- char *new_id;
- if (type == IF_IDE || type == IF_SCSI) {
- mediastr = (media == MEDIA_CDROM) ? "-cd" : "-hd";
- }
- if (max_devs) {
- new_id = g_strdup_printf("%s%i%s%i", if_name[type], bus_id,
- mediastr, unit_id);
- } else {
- new_id = g_strdup_printf("%s%s%i", if_name[type],
- mediastr, unit_id);
- }
- qemu_opts_set_id(opts, new_id);
- }
-
/* init */
dinfo = g_malloc0(sizeof(*dinfo));
dinfo->id = g_strdup(qemu_opts_id(opts));
@@ -554,8 +484,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
dinfo->bdrv->read_only = ro;
dinfo->devaddr = devaddr;
dinfo->type = type;
- dinfo->bus = bus_id;
- dinfo->unit = unit_id;
dinfo->refcount = 1;
if (serial != NULL) {
dinfo->serial = g_strdup(serial);
@@ -681,6 +609,18 @@ QemuOptsList qemu_legacy_drive_opts = {
.head = QTAILQ_HEAD_INITIALIZER(qemu_legacy_drive_opts.head),
.desc = {
{
+ .name = "bus",
+ .type = QEMU_OPT_NUMBER,
+ .help = "bus number",
+ },{
+ .name = "unit",
+ .type = QEMU_OPT_NUMBER,
+ .help = "unit number (i.e. lun for scsi)",
+ },{
+ .name = "index",
+ .type = QEMU_OPT_NUMBER,
+ .help = "index number",
+ },{
.name = "media",
.type = QEMU_OPT_STRING,
.help = "media type (disk, cdrom)",
@@ -722,6 +662,7 @@ DriveInfo *drive_init(QemuOpts *all_opts,
BlockInterfaceType block_default_type)
DriveMediaType media = MEDIA_DISK;
BlockInterfaceType type;
int cyls, heads, secs, translation;
+ int max_devs, bus_id, unit_id, index;
Error *local_err = NULL;
/* Change legacy command line options into QMP ones */
@@ -865,6 +806,63 @@ DriveInfo *drive_init(QemuOpts *all_opts,
BlockInterfaceType block_default_type)
}
}
+ /* Device address specified by bus/unit or index.
+ * If none was specified, try to find the first free one. */
+ bus_id = qemu_opt_get_number(legacy_opts, "bus", 0);
+ unit_id = qemu_opt_get_number(legacy_opts, "unit", -1);
+ index = qemu_opt_get_number(legacy_opts, "index", -1);
+
+ max_devs = if_max_devs[type];
+
+ if (index != -1) {
+ if (bus_id != 0 || unit_id != -1) {
+ error_report("index cannot be used with bus and unit");
+ goto fail;
+ }
+ bus_id = drive_index_to_bus_id(type, index);
+ unit_id = drive_index_to_unit_id(type, index);
+ }
+
+ if (unit_id == -1) {
+ unit_id = 0;
+ while (drive_get(type, bus_id, unit_id) != NULL) {
+ unit_id++;
+ if (max_devs && unit_id >= max_devs) {
+ unit_id -= max_devs;
+ bus_id++;
+ }
+ }
+ }
+
+ if (max_devs && unit_id >= max_devs) {
+ error_report("unit %d too big (max is %d)", unit_id, max_devs - 1);
+ goto fail;
+ }
+
+ if (drive_get(type, bus_id, unit_id) != NULL) {
+ error_report("drive with bus=%d, unit=%d (index=%d) exists",
+ bus_id, unit_id, index);
+ goto fail;
+ }
+
+ /* no id supplied -> create one */
+ if (qemu_opts_id(all_opts) == NULL) {
+ char *new_id;
+ const char *mediastr = "";
+ if (type == IF_IDE || type == IF_SCSI) {
+ mediastr = (media == MEDIA_CDROM) ? "-cd" : "-hd";
+ }
+ if (max_devs) {
+ new_id = g_strdup_printf("%s%i%s%i", if_name[type], bus_id,
+ mediastr, unit_id);
+ } else {
+ new_id = g_strdup_printf("%s%s%i", if_name[type],
+ mediastr, unit_id);
+ }
+ qdict_put(bs_opts, "id", qstring_from_str(new_id));
+ g_free(new_id);
+ }
+
/* Actual block device init: Functionality shared with blockdev-add */
dinfo = blockdev_init(bs_opts, type, media);
if (dinfo == NULL) {
@@ -880,6 +878,9 @@ DriveInfo *drive_init(QemuOpts *all_opts,
BlockInterfaceType block_default_type)
dinfo->secs = secs;
dinfo->trans = translation;
+ dinfo->bus = bus_id;
+ dinfo->unit = unit_id;
+
fail:
qemu_opts_del(legacy_opts);
return dinfo;
@@ -2211,18 +2212,6 @@ QemuOptsList qemu_common_drive_opts = {
.head = QTAILQ_HEAD_INITIALIZER(qemu_common_drive_opts.head),
.desc = {
{
- .name = "bus",
- .type = QEMU_OPT_NUMBER,
- .help = "bus number",
- },{
- .name = "unit",
- .type = QEMU_OPT_NUMBER,
- .help = "unit number (i.e. lun for scsi)",
- },{
- .name = "index",
- .type = QEMU_OPT_NUMBER,
- .help = "index number",
- },{
.name = "snapshot",
.type = QEMU_OPT_BOOL,
.help = "enable/disable snapshot mode",
--
1.8.1.4
- [Qemu-devel] [PATCH 07/17] blockdev: Move parsing of 'media' option to drive_init, (continued)
- [Qemu-devel] [PATCH 07/17] blockdev: Move parsing of 'media' option to drive_init, Kevin Wolf, 2013/09/20
- [Qemu-devel] [PATCH 08/17] blockdev: Move parsing of 'if' option to drive_init, Kevin Wolf, 2013/09/20
- [Qemu-devel] [PATCH 09/17] blockdev: Moving parsing of geometry options to drive_init, Kevin Wolf, 2013/09/20
- [Qemu-devel] [PATCH 10/17] blockdev: Move parsing of 'boot' option to drive_init, Kevin Wolf, 2013/09/20
- [Qemu-devel] [PATCH 11/17] blockdev: Move bus/unit/index processing to drive_init,
Kevin Wolf <=
- [Qemu-devel] [PATCH 12/17] blockdev: Move virtio-blk device creation to drive_init, Kevin Wolf, 2013/09/20
- [Qemu-devel] [PATCH 13/17] blockdev: Remove IF_* check for read-only blockdev_init, Kevin Wolf, 2013/09/20
- [Qemu-devel] [PATCH 14/17] qemu-iotests: Check autodel behaviour for device_del, Kevin Wolf, 2013/09/20
- [Qemu-devel] [PATCH 15/17] blockdev: Remove 'media' parameter from blockdev_init(), Kevin Wolf, 2013/09/20