Blame SOURCES/kvm-blockdev-Moving-parsing-of-geometry-options-to-drive.patch

218e99
From b434963222bd7ce4b4a7ff493217f3ab00ac734c Mon Sep 17 00:00:00 2001
218e99
From: Kevin Wolf <kwolf@redhat.com>
218e99
Date: Tue, 5 Nov 2013 14:09:06 +0100
218e99
Subject: [PATCH 53/87] blockdev: Moving parsing of geometry options to drive_init
218e99
218e99
RH-Author: Kevin Wolf <kwolf@redhat.com>
218e99
Message-id: <1383660558-32096-13-git-send-email-kwolf@redhat.com>
218e99
Patchwork-id: 55391
218e99
O-Subject: [RHEL-7.0 qemu-kvm PATCH 12/24] blockdev: Moving parsing of geometry options 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 moves all of the geometry options (cyls/heads/secs/trans) to
218e99
drive_init so that they can only be accessed using legacy functions, but
218e99
never with anything blockdev-add related.
218e99
218e99
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
218e99
Reviewed-by: Eric Blake <eblake@redhat.com>
218e99
(cherry picked from commit b41a7338cfdeeb913ee4846d79a3f7e221350aed)
218e99
218e99
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
218e99
---
218e99
 blockdev.c | 136 +++++++++++++++++++++++++++++++------------------------------
218e99
 1 file changed, 69 insertions(+), 67 deletions(-)
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 blockdev.c |  136 ++++++++++++++++++++++++++++++-----------------------------
218e99
 1 files changed, 69 insertions(+), 67 deletions(-)
218e99
218e99
diff --git a/blockdev.c b/blockdev.c
218e99
index 9bc3417..d69c4a8 100644
218e99
--- a/blockdev.c
218e99
+++ b/blockdev.c
218e99
@@ -336,7 +336,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
218e99
     const char *serial;
218e99
     const char *mediastr = "";
218e99
     int bus_id, unit_id;
218e99
-    int cyls, heads, secs, translation;
218e99
     int max_devs;
218e99
     int index;
218e99
     int ro = 0;
218e99
@@ -354,8 +353,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
218e99
     bool has_driver_specific_opts;
218e99
     BlockDriver *drv = NULL;
218e99
 
218e99
-    translation = BIOS_ATA_TRANSLATION_AUTO;
218e99
-
218e99
     /* Check common options by copying from bs_opts to opts, all other options
218e99
      * stay in bs_opts for processing by bdrv_open(). */
218e99
     id = qdict_get_try_str(bs_opts, "id");
218e99
@@ -384,10 +381,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
218e99
     unit_id = qemu_opt_get_number(opts, "unit", -1);
218e99
     index   = qemu_opt_get_number(opts, "index", -1);
218e99
 
218e99
-    cyls  = qemu_opt_get_number(opts, "cyls", 0);
218e99
-    heads = qemu_opt_get_number(opts, "heads", 0);
218e99
-    secs  = qemu_opt_get_number(opts, "secs", 0);
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
@@ -397,46 +390,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
218e99
 
218e99
     max_devs = if_max_devs[type];
218e99
 
218e99
-    if (cyls || heads || secs) {
218e99
-        if (cyls < 1) {
218e99
-            error_report("invalid physical cyls number");
218e99
-	    return NULL;
218e99
-	}
218e99
-        if (heads < 1) {
218e99
-            error_report("invalid physical heads number");
218e99
-	    return NULL;
218e99
-	}
218e99
-        if (secs < 1) {
218e99
-            error_report("invalid physical secs number");
218e99
-	    return NULL;
218e99
-	}
218e99
-    }
218e99
-
218e99
-    if ((buf = qemu_opt_get(opts, "trans")) != NULL) {
218e99
-        if (!cyls) {
218e99
-            error_report("'%s' trans must be used with cyls, heads and secs",
218e99
-                         buf);
218e99
-            return NULL;
218e99
-        }
218e99
-        if (!strcmp(buf, "none"))
218e99
-            translation = BIOS_ATA_TRANSLATION_NONE;
218e99
-        else if (!strcmp(buf, "lba"))
218e99
-            translation = BIOS_ATA_TRANSLATION_LBA;
218e99
-        else if (!strcmp(buf, "auto"))
218e99
-            translation = BIOS_ATA_TRANSLATION_AUTO;
218e99
-	else {
218e99
-            error_report("'%s' invalid translation type", buf);
218e99
-	    return NULL;
218e99
-	}
218e99
-    }
218e99
-
218e99
-    if (media == MEDIA_CDROM) {
218e99
-        if (cyls || secs || heads) {
218e99
-            error_report("CHS can't be set with media=cdrom");
218e99
-            return NULL;
218e99
-        }
218e99
-    }
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
@@ -612,10 +565,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
218e99
     dinfo->type = type;
218e99
     dinfo->bus = bus_id;
218e99
     dinfo->unit = unit_id;
218e99
-    dinfo->cyls = cyls;
218e99
-    dinfo->heads = heads;
218e99
-    dinfo->secs = secs;
218e99
-    dinfo->trans = translation;
218e99
     dinfo->refcount = 1;
218e99
     if (serial != NULL) {
218e99
         dinfo->serial = g_strdup(serial);
218e99
@@ -745,6 +694,22 @@ QemuOptsList qemu_legacy_drive_opts = {
218e99
             .name = "if",
218e99
             .type = QEMU_OPT_STRING,
218e99
             .help = "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)",
218e99
+        },{
218e99
+            .name = "cyls",
218e99
+            .type = QEMU_OPT_NUMBER,
218e99
+            .help = "number of cylinders (ide disk geometry)",
218e99
+        },{
218e99
+            .name = "heads",
218e99
+            .type = QEMU_OPT_NUMBER,
218e99
+            .help = "number of heads (ide disk geometry)",
218e99
+        },{
218e99
+            .name = "secs",
218e99
+            .type = QEMU_OPT_NUMBER,
218e99
+            .help = "number of sectors (ide disk geometry)",
218e99
+        },{
218e99
+            .name = "trans",
218e99
+            .type = QEMU_OPT_STRING,
218e99
+            .help = "chs translation (auto, lba, none)",
218e99
         },
218e99
         { /* end of list */ }
218e99
     },
218e99
@@ -758,6 +723,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
218e99
     QemuOpts *legacy_opts;
218e99
     DriveMediaType media = MEDIA_DISK;
218e99
     BlockInterfaceType type;
218e99
+    int cyls, heads, secs, translation;
218e99
     Error *local_err = NULL;
218e99
 
218e99
     /* Change legacy command line options into QMP ones */
218e99
@@ -836,6 +802,53 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
218e99
         type = block_default_type;
218e99
     }
218e99
 
218e99
+    /* Geometry */
218e99
+    cyls  = qemu_opt_get_number(legacy_opts, "cyls", 0);
218e99
+    heads = qemu_opt_get_number(legacy_opts, "heads", 0);
218e99
+    secs  = qemu_opt_get_number(legacy_opts, "secs", 0);
218e99
+
218e99
+    if (cyls || heads || secs) {
218e99
+        if (cyls < 1) {
218e99
+            error_report("invalid physical cyls number");
218e99
+            goto fail;
218e99
+        }
218e99
+        if (heads < 1) {
218e99
+            error_report("invalid physical heads number");
218e99
+            goto fail;
218e99
+        }
218e99
+        if (secs < 1) {
218e99
+            error_report("invalid physical secs number");
218e99
+            goto fail;
218e99
+        }
218e99
+    }
218e99
+
218e99
+    translation = BIOS_ATA_TRANSLATION_AUTO;
218e99
+    value = qemu_opt_get(legacy_opts, "trans");
218e99
+    if (value != NULL) {
218e99
+        if (!cyls) {
218e99
+            error_report("'%s' trans must be used with cyls, heads and secs",
218e99
+                         value);
218e99
+            goto fail;
218e99
+        }
218e99
+        if (!strcmp(value, "none")) {
218e99
+            translation = BIOS_ATA_TRANSLATION_NONE;
218e99
+        } else if (!strcmp(value, "lba")) {
218e99
+            translation = BIOS_ATA_TRANSLATION_LBA;
218e99
+        } else if (!strcmp(value, "auto")) {
218e99
+            translation = BIOS_ATA_TRANSLATION_AUTO;
218e99
+        } else {
218e99
+            error_report("'%s' invalid translation type", value);
218e99
+            goto fail;
218e99
+        }
218e99
+    }
218e99
+
218e99
+    if (media == MEDIA_CDROM) {
218e99
+        if (cyls || secs || heads) {
218e99
+            error_report("CHS can't be set with media=cdrom");
218e99
+            goto fail;
218e99
+        }
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
@@ -846,6 +859,11 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
218e99
     dinfo->enable_auto_del = true;
218e99
     dinfo->opts = all_opts;
218e99
 
218e99
+    dinfo->cyls = cyls;
218e99
+    dinfo->heads = heads;
218e99
+    dinfo->secs = secs;
218e99
+    dinfo->trans = translation;
218e99
+
218e99
 fail:
218e99
     qemu_opts_del(legacy_opts);
218e99
     return dinfo;
218e99
@@ -1793,22 +1811,6 @@ QemuOptsList qemu_common_drive_opts = {
218e99
             .type = QEMU_OPT_NUMBER,
218e99
             .help = "index number",
218e99
         },{
218e99
-            .name = "cyls",
218e99
-            .type = QEMU_OPT_NUMBER,
218e99
-            .help = "number of cylinders (ide disk geometry)",
218e99
-        },{
218e99
-            .name = "heads",
218e99
-            .type = QEMU_OPT_NUMBER,
218e99
-            .help = "number of heads (ide disk geometry)",
218e99
-        },{
218e99
-            .name = "secs",
218e99
-            .type = QEMU_OPT_NUMBER,
218e99
-            .help = "number of sectors (ide disk geometry)",
218e99
-        },{
218e99
-            .name = "trans",
218e99
-            .type = QEMU_OPT_STRING,
218e99
-            .help = "chs translation (auto, lba. none)",
218e99
-        },{
218e99
             .name = "snapshot",
218e99
             .type = QEMU_OPT_BOOL,
218e99
             .help = "enable/disable snapshot mode",
218e99
-- 
218e99
1.7.1
218e99