qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, blauwirbel@gmail.com,
	stefanha@linux.vnet.ibm.com, pbonzini@redhat.com
Subject: [Qemu-devel] [PATCH 10/32] hd-geometry: Unnest conditional in hd_geometry_guess()
Date: Fri,  6 Jul 2012 08:57:48 +0200	[thread overview]
Message-ID: <1341557890-17464-11-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1341557890-17464-1-git-send-email-armbru@redhat.com>


Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/hd-geometry.c |   84 +++++++++++++++++++++++++++---------------------------
 1 files changed, 42 insertions(+), 42 deletions(-)

diff --git a/hw/hd-geometry.c b/hw/hd-geometry.c
index f0dd021..db47846 100644
--- a/hw/hd-geometry.c
+++ b/hw/hd-geometry.c
@@ -104,58 +104,58 @@ void hd_geometry_guess(BlockDriverState *bs,
     int cylinders, heads, secs;
     uint64_t nb_sectors;
 
-    /* if a geometry hint is available, use it */
     bdrv_get_geometry(bs, &nb_sectors);
     bdrv_get_geometry_hint(bs, &cylinders, &heads, &secs);
     translation = bdrv_get_translation_hint(bs);
+
     if (cylinders != 0) {
+        /* already got a geometry hint: use it */
         *pcyls = cylinders;
         *pheads = heads;
         *psecs = secs;
-    } else {
-        if (guess_disk_lchs(bs, &cylinders, &heads, &secs) == 0) {
-            if (heads > 16) {
-                /* if heads > 16, it means that a BIOS LBA
-                   translation was active, so the default
-                   hardware geometry is OK */
-                lba_detected = 1;
-                goto default_geometry;
-            } else {
-                *pcyls = cylinders;
-                *pheads = heads;
-                *psecs = secs;
-                /* disable any translation to be in sync with
-                   the logical geometry */
-                if (translation == BIOS_ATA_TRANSLATION_AUTO) {
-                    bdrv_set_translation_hint(bs,
-                                              BIOS_ATA_TRANSLATION_NONE);
-                }
-            }
-        } else {
-        default_geometry:
-            /* if no geometry, use a standard physical disk geometry */
-            cylinders = nb_sectors / (16 * 63);
+        return;
+    }
 
-            if (cylinders > 16383) {
-                cylinders = 16383;
-            } else if (cylinders < 2) {
-                cylinders = 2;
-            }
-            *pcyls = cylinders;
-            *pheads = 16;
-            *psecs = 63;
-            if ((lba_detected == 1)
-                && (translation == BIOS_ATA_TRANSLATION_AUTO)) {
-                if ((*pcyls * *pheads) <= 131072) {
-                    bdrv_set_translation_hint(bs,
-                                              BIOS_ATA_TRANSLATION_LARGE);
-                } else {
-                    bdrv_set_translation_hint(bs,
-                                              BIOS_ATA_TRANSLATION_LBA);
-                }
+    if (guess_disk_lchs(bs, &cylinders, &heads, &secs) < 0) {
+        /* no LCHS guess: use a standard physical disk geometry  */
+    default_geometry:
+        cylinders = nb_sectors / (16 * 63);
+
+        if (cylinders > 16383) {
+            cylinders = 16383;
+        } else if (cylinders < 2) {
+            cylinders = 2;
+        }
+        *pcyls = cylinders;
+        *pheads = 16;
+        *psecs = 63;
+        if ((lba_detected == 1) && (translation == BIOS_ATA_TRANSLATION_AUTO)) {
+            if ((*pcyls * *pheads) <= 131072) {
+                bdrv_set_translation_hint(bs,
+                                          BIOS_ATA_TRANSLATION_LARGE);
+            } else {
+                bdrv_set_translation_hint(bs,
+                                          BIOS_ATA_TRANSLATION_LBA);
             }
         }
-        bdrv_set_geometry_hint(bs, *pcyls, *pheads, *psecs);
+    } else if (heads > 16) {
+        /* LCHS guess with heads > 16 means that a BIOS LBA
+           translation was active, so a standard physical disk
+           geometry is OK */
+        lba_detected = 1;
+        goto default_geometry;
+    } else {
+        /* LCHS guess with heads <= 16: use as physical geometry */
+        *pcyls = cylinders;
+        *pheads = heads;
+        *psecs = secs;
+        /* disable any translation to be in sync with
+           the logical geometry */
+        if (translation == BIOS_ATA_TRANSLATION_AUTO) {
+            bdrv_set_translation_hint(bs,
+                                      BIOS_ATA_TRANSLATION_NONE);
+        }
     }
+    bdrv_set_geometry_hint(bs, *pcyls, *pheads, *psecs);
     trace_hd_geometry_guess(bs, *pcyls, *pheads, *psecs, translation);
 }
-- 
1.7.6.5

  parent reply	other threads:[~2012-07-06  6:58 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-06  6:57 [Qemu-devel] [PATCH 00/32] Disk geometry cleanup Markus Armbruster
2012-07-06  6:57 ` [Qemu-devel] [PATCH 01/32] fdc: Drop broken code for user-defined floppy geometry Markus Armbruster
2012-07-06  6:57 ` [Qemu-devel] [PATCH 02/32] fdc: Move floppy geometry guessing back from block.c Markus Armbruster
2012-07-06  6:57 ` [Qemu-devel] [PATCH 03/32] vvfat: Fix partition table Markus Armbruster
2012-07-06  6:57 ` [Qemu-devel] [PATCH 04/32] vvfat: Do not clobber the user's geometry Markus Armbruster
2012-07-06  6:57 ` [Qemu-devel] [PATCH 05/32] qtest: Tidy up temporary files properly Markus Armbruster
2012-07-07  7:39   ` Blue Swirl
2012-07-09  7:56     ` Markus Armbruster
2012-07-09  9:09       ` Kevin Wolf
2012-07-06  6:57 ` [Qemu-devel] [PATCH 06/32] qtest: Add hard disk geometry test Markus Armbruster
2012-07-06  6:57 ` [Qemu-devel] [PATCH 07/32] block: Factor bdrv_read_unthrottled() out of guess_disk_lchs() Markus Armbruster
2012-07-06  6:57 ` [Qemu-devel] [PATCH 08/32] hd-geometry: Move disk geometry guessing back from block.c Markus Armbruster
2012-07-06  6:57 ` [Qemu-devel] [PATCH 09/32] hd-geometry: Add tracepoints Markus Armbruster
2012-07-06  6:57 ` Markus Armbruster [this message]
2012-07-06  6:57 ` [Qemu-devel] [PATCH 11/32] hd-geometry: Factor out guess_chs_for_size() Markus Armbruster
2012-07-06  6:57 ` [Qemu-devel] [PATCH 12/32] hd-geometry: Clean up gratuitous goto in hd_geometry_guess() Markus Armbruster
2012-07-06  6:57 ` [Qemu-devel] [PATCH 13/32] hd-geometry: Clean up confusing use of prior translation hint Markus Armbruster
2012-07-06  6:57 ` [Qemu-devel] [PATCH 14/32] hd-geometry: Cut out block layer translation middleman Markus Armbruster
2012-07-06  6:57 ` [Qemu-devel] [PATCH 15/32] ide pc: Cut out the block layer geometry middleman Markus Armbruster
2012-07-06  6:57 ` [Qemu-devel] [PATCH 16/32] blockdev: Save geometry in DriveInfo Markus Armbruster
2012-07-06  6:57 ` [Qemu-devel] [PATCH 17/32] qdev: Introduce block geometry properties Markus Armbruster
2012-07-06  6:57 ` [Qemu-devel] [PATCH 18/32] hd-geometry: Switch to uint32_t to match BlockConf Markus Armbruster
2012-07-06  6:57 ` [Qemu-devel] [PATCH 19/32] scsi-hd: qdev properties for disk geometry Markus Armbruster
2012-07-06  6:57 ` [Qemu-devel] [PATCH 20/32] virtio-blk: " Markus Armbruster
2012-07-06  6:57 ` [Qemu-devel] [PATCH 21/32] ide: " Markus Armbruster
2012-07-06  6:58 ` [Qemu-devel] [PATCH 22/32] qtest: Cover " Markus Armbruster
2012-07-06  6:58 ` [Qemu-devel] [PATCH 23/32] qdev: Collect private helpers in one place Markus Armbruster
2012-07-06  6:58 ` [Qemu-devel] [PATCH 24/32] qdev: New property type chs-translation Markus Armbruster
2012-07-06  6:58 ` [Qemu-devel] [PATCH 25/32] ide: qdev property for BIOS CHS translation Markus Armbruster
2012-07-06  6:58 ` [Qemu-devel] [PATCH 26/32] qtest: Cover " Markus Armbruster
2012-07-06  6:58 ` [Qemu-devel] [PATCH 27/32] block: Geometry and translation hints are now useless, purge them Markus Armbruster
2012-07-06  6:58 ` [Qemu-devel] [PATCH 28/32] ide pc: Put hard disk info into CMOS only for hard disks Markus Armbruster
2012-07-06  6:58 ` [Qemu-devel] [PATCH 29/32] qtest: Test we don't put hard disk info into CMOS for a CD-ROM Markus Armbruster
2012-07-06  6:58 ` [Qemu-devel] [PATCH 30/32] hd-geometry: Compute BIOS CHS translation in one place Markus Armbruster
2012-07-06  6:58 ` [Qemu-devel] [PATCH 31/32] blockdev: Drop redundant CHS validation for if=ide Markus Armbruster
2012-07-06  6:58 ` [Qemu-devel] [PATCH 32/32] Relax IDE CHS limits from 16383, 16, 63 to 65535, 16, 255 Markus Armbruster
2012-07-06  7:28 ` [Qemu-devel] [PATCH 00/32] Disk geometry cleanup Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1341557890-17464-11-git-send-email-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=blauwirbel@gmail.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).