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 v3 16/29] scsi-hd: qdev properties for disk geometry
Date: Tue, 10 Jul 2012 11:12:42 +0200	[thread overview]
Message-ID: <1341911575-7306-17-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1341911575-7306-1-git-send-email-armbru@redhat.com>

Geometry needs to be qdev properties, because it belongs to the
disk's guest part.

Maintain backward compatibility exactly like for serial: fall back to
DriveInfo's geometry, set with -drive cyls=...

Do this only for scsi-hd.  scsi-disk is legacy.  scsi-cd doesn't have
a geometry.  scsi-block should get geometry from the host disk.

Bonus: info qtree now shows the geometry.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/scsi-disk.c |   69 +++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 46 insertions(+), 23 deletions(-)

diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index c881acf..0a182f9 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -966,9 +966,6 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf,
         [MODE_PAGE_AUDIO_CTL]              = (1 << TYPE_ROM),
         [MODE_PAGE_CAPABILITIES]           = (1 << TYPE_ROM),
     };
-
-    BlockDriverState *bdrv = s->qdev.conf.bs;
-    uint32_t cylinders, heads, secs;
     uint8_t *p = *p_outbuf;
 
     if ((mode_sense_valid[page] & (1 << s->qdev.type)) == 0) {
@@ -990,19 +987,18 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf,
             break;
         }
         /* if a geometry hint is available, use it */
-        hd_geometry_guess(bdrv, &cylinders, &heads, &secs, NULL);
-        p[2] = (cylinders >> 16) & 0xff;
-        p[3] = (cylinders >> 8) & 0xff;
-        p[4] = cylinders & 0xff;
-        p[5] = heads & 0xff;
+        p[2] = (s->qdev.conf.cyls >> 16) & 0xff;
+        p[3] = (s->qdev.conf.cyls >> 8) & 0xff;
+        p[4] = s->qdev.conf.cyls & 0xff;
+        p[5] = s->qdev.conf.heads & 0xff;
         /* Write precomp start cylinder, disabled */
-        p[6] = (cylinders >> 16) & 0xff;
-        p[7] = (cylinders >> 8) & 0xff;
-        p[8] = cylinders & 0xff;
+        p[6] = (s->qdev.conf.cyls >> 16) & 0xff;
+        p[7] = (s->qdev.conf.cyls >> 8) & 0xff;
+        p[8] = s->qdev.conf.cyls & 0xff;
         /* Reduced current start cylinder, disabled */
-        p[9] = (cylinders >> 16) & 0xff;
-        p[10] = (cylinders >> 8) & 0xff;
-        p[11] = cylinders & 0xff;
+        p[9] = (s->qdev.conf.cyls >> 16) & 0xff;
+        p[10] = (s->qdev.conf.cyls >> 8) & 0xff;
+        p[11] = s->qdev.conf.cyls & 0xff;
         /* Device step rate [ns], 200ns */
         p[12] = 0;
         p[13] = 200;
@@ -1024,18 +1020,17 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf,
         p[2] = 5000 >> 8;
         p[3] = 5000 & 0xff;
         /* if a geometry hint is available, use it */
-        hd_geometry_guess(bdrv, &cylinders, &heads, &secs, NULL);
-        p[4] = heads & 0xff;
-        p[5] = secs & 0xff;
+        p[4] = s->qdev.conf.heads & 0xff;
+        p[5] = s->qdev.conf.secs & 0xff;
         p[6] = s->qdev.blocksize >> 8;
-        p[8] = (cylinders >> 8) & 0xff;
-        p[9] = cylinders & 0xff;
+        p[8] = (s->qdev.conf.cyls >> 8) & 0xff;
+        p[9] = s->qdev.conf.cyls & 0xff;
         /* Write precomp start cylinder, disabled */
-        p[10] = (cylinders >> 8) & 0xff;
-        p[11] = cylinders & 0xff;
+        p[10] = (s->qdev.conf.cyls >> 8) & 0xff;
+        p[11] = s->qdev.conf.cyls & 0xff;
         /* Reduced current start cylinder, disabled */
-        p[12] = (cylinders >> 8) & 0xff;
-        p[13] = cylinders & 0xff;
+        p[12] = (s->qdev.conf.cyls >> 8) & 0xff;
+        p[13] = s->qdev.conf.cyls & 0xff;
         /* Device step rate [100us], 100us */
         p[14] = 0;
         p[15] = 1;
@@ -1755,6 +1750,33 @@ static int scsi_initfn(SCSIDevice *dev)
         return -1;
     }
 
+    if (!dev->conf.cyls && !dev->conf.heads && !dev->conf.secs) {
+        /* try to fall back to value set with legacy -drive cyls=... */
+        dinfo = drive_get_by_blockdev(s->qdev.conf.bs);
+        dev->conf.cyls = dinfo->cyls;
+        dev->conf.heads = dinfo->heads;
+        dev->conf.secs = dinfo->secs;
+    }
+    if (!dev->conf.cyls && !dev->conf.heads && !dev->conf.secs) {
+        hd_geometry_guess(s->qdev.conf.bs,
+                          &dev->conf.cyls, &dev->conf.heads, &dev->conf.secs,
+                          NULL);
+    }
+    if (dev->conf.cyls || dev->conf.heads || dev->conf.secs) {
+        if (dev->conf.cyls < 1 || dev->conf.cyls > 65535) {
+            error_report("cyls must be between 1 and 65535");
+            return -1;
+        }
+        if (dev->conf.heads < 1 || dev->conf.heads > 255) {
+            error_report("heads must be between 1 and 255");
+            return -1;
+        }
+        if (dev->conf.secs < 1 || dev->conf.secs > 255) {
+            error_report("secs must be between 1 and 255");
+            return -1;
+        }
+    }
+
     if (!s->serial) {
         /* try to fall back to value set with legacy -drive serial=... */
         dinfo = drive_get_by_blockdev(s->qdev.conf.bs);
@@ -1975,6 +1997,7 @@ static Property scsi_hd_properties[] = {
     DEFINE_PROP_BIT("dpofua", SCSIDiskState, features,
                     SCSI_DISK_F_DPOFUA, false),
     DEFINE_PROP_HEX64("wwn", SCSIDiskState, wwn, 0),
+    DEFINE_BLOCK_CHS_PROPERTIES(SCSIDiskState, qdev.conf),
     DEFINE_PROP_END_OF_LIST(),
 };
 
-- 
1.7.6.5

  parent reply	other threads:[~2012-07-10  9:13 UTC|newest]

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

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=1341911575-7306-17-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).