From patchwork Fri Jul 6 06:57:57 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 169363 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 931222C0083 for ; Fri, 6 Jul 2012 18:13:53 +1000 (EST) Received: from localhost ([::1]:60314 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sn2VU-0004gt-3l for incoming@patchwork.ozlabs.org; Fri, 06 Jul 2012 02:59:12 -0400 Received: from eggs.gnu.org ([208.118.235.92]:40111) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sn2Ug-00037g-Ie for qemu-devel@nongnu.org; Fri, 06 Jul 2012 02:58:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sn2Ud-0003Ot-Q1 for qemu-devel@nongnu.org; Fri, 06 Jul 2012 02:58:22 -0400 Received: from oxygen.pond.sub.org ([78.46.104.156]:50629) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sn2Ud-0003Ns-DH for qemu-devel@nongnu.org; Fri, 06 Jul 2012 02:58:19 -0400 Received: from blackfin.pond.sub.org (p5B32A0DA.dip.t-dialin.net [91.50.160.218]) by oxygen.pond.sub.org (Postfix) with ESMTPA id 5CBAAA5A6A; Fri, 6 Jul 2012 08:58:16 +0200 (CEST) Received: by blackfin.pond.sub.org (Postfix, from userid 500) id 8ECC0600B0; Fri, 6 Jul 2012 08:58:11 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 6 Jul 2012 08:57:57 +0200 Message-Id: <1341557890-17464-20-git-send-email-armbru@redhat.com> X-Mailer: git-send-email 1.7.6.5 In-Reply-To: <1341557890-17464-1-git-send-email-armbru@redhat.com> References: <1341557890-17464-1-git-send-email-armbru@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 78.46.104.156 Cc: kwolf@redhat.com, blauwirbel@gmail.com, stefanha@linux.vnet.ibm.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH 19/32] scsi-hd: qdev properties for disk geometry X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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 bb758f2..b48a4fa 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -925,9 +925,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) { @@ -949,19 +946,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; @@ -983,18 +979,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; @@ -1707,6 +1702,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); @@ -1926,6 +1948,7 @@ static Property scsi_hd_properties[] = { SCSI_DISK_F_REMOVABLE, false), DEFINE_PROP_BIT("dpofua", SCSIDiskState, features, SCSI_DISK_F_DPOFUA, false), + DEFINE_BLOCK_CHS_PROPERTIES(SCSIDiskState, qdev.conf), DEFINE_PROP_END_OF_LIST(), };