cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-blockdev-Move-bus-unit-index-processing-to-drive_ini.patch

218e99
From 9ab9b4d966cf80520ad0864bc61b1d3a255ce39c Mon Sep 17 00:00:00 2001
218e99
From: Kevin Wolf <kwolf@redhat.com>
218e99
Date: Tue, 5 Nov 2013 14:09:08 +0100
218e99
Subject: [PATCH 55/87] blockdev: Move bus/unit/index processing to drive_init
218e99
218e99
RH-Author: Kevin Wolf <kwolf@redhat.com>
218e99
Message-id: <1383660558-32096-15-git-send-email-kwolf@redhat.com>
218e99
Patchwork-id: 55393
218e99
O-Subject: [RHEL-7.0 qemu-kvm PATCH 14/24] blockdev: Move bus/unit/index processing to drive_init
218e99
Bugzilla: 978402
218e99
RH-Acked-by: Fam Zheng <famz@redhat.com>
218e99
RH-Acked-by: Max Reitz <mreitz@redhat.com>
218e99
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
218e99
218e99
This requires moving the automatic ID generation at the same time, so
218e99
let's do that as well.
218e99
218e99
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
218e99
Reviewed-by: Max Reitz <mreitz@redhat.com>
218e99
Reviewed-by: Eric Blake <eblake@redhat.com>
218e99
(cherry picked from commit 87a899c5090c7864fc7dcff3ea0ac34153ea621b)
218e99
218e99
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
218e99
---
218e99
 blockdev.c | 157 ++++++++++++++++++++++++++++---------------------------------
218e99
 1 file changed, 73 insertions(+), 84 deletions(-)
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 blockdev.c |  157 ++++++++++++++++++++++++++++--------------------------------
218e99
 1 files changed, 73 insertions(+), 84 deletions(-)
218e99
218e99
diff --git a/blockdev.c b/blockdev.c
218e99
index 9f9cbba..b6dff50 100644
218e99
--- a/blockdev.c
218e99
+++ b/blockdev.c
218e99
@@ -334,10 +334,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
218e99
     const char *buf;
218e99
     const char *file = NULL;
218e99
     const char *serial;
218e99
-    const char *mediastr = "";
218e99
-    int bus_id, unit_id;
218e99
-    int max_devs;
218e99
-    int index;
218e99
     int ro = 0;
218e99
     int bdrv_flags = 0;
218e99
     int on_read_error, on_write_error;
218e99
@@ -377,10 +373,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
218e99
     has_driver_specific_opts = !!qdict_size(bs_opts);
218e99
 
218e99
     /* extract parameters */
218e99
-    bus_id  = qemu_opt_get_number(opts, "bus", 0);
218e99
-    unit_id = qemu_opt_get_number(opts, "unit", -1);
218e99
-    index   = qemu_opt_get_number(opts, "index", -1);
218e99
-
218e99
     snapshot = qemu_opt_get_bool(opts, "snapshot", 0);
218e99
     ro = qemu_opt_get_bool(opts, "read-only", 0);
218e99
     copy_on_read = qemu_opt_get_bool(opts, "copy-on-read", false);
218e99
@@ -388,8 +380,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
218e99
     file = qemu_opt_get(opts, "file");
218e99
     serial = qemu_opt_get(opts, "serial");
218e99
 
218e99
-    max_devs = if_max_devs[type];
218e99
-
218e99
     if ((buf = qemu_opt_get(opts, "discard")) != NULL) {
218e99
         if (bdrv_parse_discard_flags(buf, &bdrv_flags) != 0) {
218e99
             error_report("invalid discard option");
218e99
@@ -489,66 +479,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
218e99
         }
218e99
     }
218e99
 
218e99
-    /* compute bus and unit according index */
218e99
-
218e99
-    if (index != -1) {
218e99
-        if (bus_id != 0 || unit_id != -1) {
218e99
-            error_report("index cannot be used with bus and unit");
218e99
-            return NULL;
218e99
-        }
218e99
-        bus_id = drive_index_to_bus_id(type, index);
218e99
-        unit_id = drive_index_to_unit_id(type, index);
218e99
-    }
218e99
-
218e99
-    /* if user doesn't specify a unit_id,
218e99
-     * try to find the first free
218e99
-     */
218e99
-
218e99
-    if (unit_id == -1) {
218e99
-       unit_id = 0;
218e99
-       while (drive_get(type, bus_id, unit_id) != NULL) {
218e99
-           unit_id++;
218e99
-           if (max_devs && unit_id >= max_devs) {
218e99
-               unit_id -= max_devs;
218e99
-               bus_id++;
218e99
-           }
218e99
-       }
218e99
-    }
218e99
-
218e99
-    /* check unit id */
218e99
-
218e99
-    if (max_devs && unit_id >= max_devs) {
218e99
-        error_report("unit %d too big (max is %d)",
218e99
-                     unit_id, max_devs - 1);
218e99
-        return NULL;
218e99
-    }
218e99
-
218e99
-    /*
218e99
-     * catch multiple definitions
218e99
-     */
218e99
-
218e99
-    if (drive_get(type, bus_id, unit_id) != NULL) {
218e99
-        error_report("drive with bus=%d, unit=%d (index=%d) exists",
218e99
-                     bus_id, unit_id, index);
218e99
-        return NULL;
218e99
-    }
218e99
-
218e99
-    /* no id supplied -> create one */
218e99
-    if (qemu_opts_id(opts) == NULL) {
218e99
-        char *new_id;
218e99
-        if (type == IF_IDE || type == IF_SCSI) {
218e99
-            mediastr = (media == MEDIA_CDROM) ? "-cd" : "-hd";
218e99
-        }
218e99
-        if (max_devs) {
218e99
-            new_id = g_strdup_printf("%s%i%s%i", if_name[type], bus_id,
218e99
-                                     mediastr, unit_id);
218e99
-        } else {
218e99
-            new_id = g_strdup_printf("%s%s%i", if_name[type],
218e99
-                                     mediastr, unit_id);
218e99
-        }
218e99
-        qemu_opts_set_id(opts, new_id);
218e99
-    }
218e99
-
218e99
     /* init */
218e99
     dinfo = g_malloc0(sizeof(*dinfo));
218e99
     dinfo->id = g_strdup(qemu_opts_id(opts));
218e99
@@ -557,8 +487,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
218e99
     dinfo->bdrv->read_only = ro;
218e99
     dinfo->devaddr = devaddr;
218e99
     dinfo->type = type;
218e99
-    dinfo->bus = bus_id;
218e99
-    dinfo->unit = unit_id;
218e99
     dinfo->refcount = 1;
218e99
     if (serial != NULL) {
218e99
         dinfo->serial = g_strdup(serial);
218e99
@@ -681,6 +609,18 @@ QemuOptsList qemu_legacy_drive_opts = {
218e99
     .head = QTAILQ_HEAD_INITIALIZER(qemu_legacy_drive_opts.head),
218e99
     .desc = {
218e99
         {
218e99
+            .name = "bus",
218e99
+            .type = QEMU_OPT_NUMBER,
218e99
+            .help = "bus number",
218e99
+        },{
218e99
+            .name = "unit",
218e99
+            .type = QEMU_OPT_NUMBER,
218e99
+            .help = "unit number (i.e. lun for scsi)",
218e99
+        },{
218e99
+            .name = "index",
218e99
+            .type = QEMU_OPT_NUMBER,
218e99
+            .help = "index number",
218e99
+        },{
218e99
             .name = "media",
218e99
             .type = QEMU_OPT_STRING,
218e99
             .help = "media type (disk, cdrom)",
218e99
@@ -722,6 +662,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
218e99
     DriveMediaType media = MEDIA_DISK;
218e99
     BlockInterfaceType type;
218e99
     int cyls, heads, secs, translation;
218e99
+    int max_devs, bus_id, unit_id, index;
218e99
     Error *local_err = NULL;
218e99
 
218e99
     /* Change legacy command line options into QMP ones */
218e99
@@ -854,6 +795,63 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
218e99
         }
218e99
     }
218e99
 
218e99
+    /* Device address specified by bus/unit or index.
218e99
+     * If none was specified, try to find the first free one. */
218e99
+    bus_id  = qemu_opt_get_number(legacy_opts, "bus", 0);
218e99
+    unit_id = qemu_opt_get_number(legacy_opts, "unit", -1);
218e99
+    index   = qemu_opt_get_number(legacy_opts, "index", -1);
218e99
+
218e99
+    max_devs = if_max_devs[type];
218e99
+
218e99
+    if (index != -1) {
218e99
+        if (bus_id != 0 || unit_id != -1) {
218e99
+            error_report("index cannot be used with bus and unit");
218e99
+            goto fail;
218e99
+        }
218e99
+        bus_id = drive_index_to_bus_id(type, index);
218e99
+        unit_id = drive_index_to_unit_id(type, index);
218e99
+    }
218e99
+
218e99
+    if (unit_id == -1) {
218e99
+       unit_id = 0;
218e99
+       while (drive_get(type, bus_id, unit_id) != NULL) {
218e99
+           unit_id++;
218e99
+           if (max_devs && unit_id >= max_devs) {
218e99
+               unit_id -= max_devs;
218e99
+               bus_id++;
218e99
+           }
218e99
+       }
218e99
+    }
218e99
+
218e99
+    if (max_devs && unit_id >= max_devs) {
218e99
+        error_report("unit %d too big (max is %d)", unit_id, max_devs - 1);
218e99
+        goto fail;
218e99
+    }
218e99
+
218e99
+    if (drive_get(type, bus_id, unit_id) != NULL) {
218e99
+        error_report("drive with bus=%d, unit=%d (index=%d) exists",
218e99
+                     bus_id, unit_id, index);
218e99
+        goto fail;
218e99
+    }
218e99
+
218e99
+    /* no id supplied -> create one */
218e99
+    if (qemu_opts_id(all_opts) == NULL) {
218e99
+        char *new_id;
218e99
+        const char *mediastr = "";
218e99
+        if (type == IF_IDE || type == IF_SCSI) {
218e99
+            mediastr = (media == MEDIA_CDROM) ? "-cd" : "-hd";
218e99
+        }
218e99
+        if (max_devs) {
218e99
+            new_id = g_strdup_printf("%s%i%s%i", if_name[type], bus_id,
218e99
+                                     mediastr, unit_id);
218e99
+        } else {
218e99
+            new_id = g_strdup_printf("%s%s%i", if_name[type],
218e99
+                                     mediastr, unit_id);
218e99
+        }
218e99
+        qdict_put(bs_opts, "id", qstring_from_str(new_id));
218e99
+        g_free(new_id);
218e99
+    }
218e99
+
218e99
     /* Actual block device init: Functionality shared with blockdev-add */
218e99
     dinfo = blockdev_init(bs_opts, type, media);
218e99
     if (dinfo == NULL) {
218e99
@@ -869,6 +867,9 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
218e99
     dinfo->secs = secs;
218e99
     dinfo->trans = translation;
218e99
 
218e99
+    dinfo->bus = bus_id;
218e99
+    dinfo->unit = unit_id;
218e99
+
218e99
 fail:
218e99
     qemu_opts_del(legacy_opts);
218e99
     return dinfo;
218e99
@@ -1804,18 +1805,6 @@ QemuOptsList qemu_common_drive_opts = {
218e99
     .head = QTAILQ_HEAD_INITIALIZER(qemu_common_drive_opts.head),
218e99
     .desc = {
218e99
         {
218e99
-            .name = "bus",
218e99
-            .type = QEMU_OPT_NUMBER,
218e99
-            .help = "bus number",
218e99
-        },{
218e99
-            .name = "unit",
218e99
-            .type = QEMU_OPT_NUMBER,
218e99
-            .help = "unit number (i.e. lun for scsi)",
218e99
-        },{
218e99
-            .name = "index",
218e99
-            .type = QEMU_OPT_NUMBER,
218e99
-            .help = "index number",
218e99
-        },{
218e99
             .name = "snapshot",
218e99
             .type = QEMU_OPT_BOOL,
218e99
             .help = "enable/disable snapshot mode",
218e99
-- 
218e99
1.7.1
218e99