From patchwork Tue Jul 17 16:00:17 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 171516 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 D6B262C00AE for ; Wed, 18 Jul 2012 03:35:07 +1000 (EST) Received: from localhost ([::1]:44359 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SrBft-00031h-T3 for incoming@patchwork.ozlabs.org; Tue, 17 Jul 2012 13:35:05 -0400 Received: from eggs.gnu.org ([208.118.235.92]:38574) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SrADB-0007SN-5A for qemu-devel@nongnu.org; Tue, 17 Jul 2012 12:01:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SrAD4-0005sT-PA for qemu-devel@nongnu.org; Tue, 17 Jul 2012 12:01:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51023) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SrAD4-0005sF-HC for qemu-devel@nongnu.org; Tue, 17 Jul 2012 12:01:14 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q6HG1DI0020037 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 17 Jul 2012 12:01:13 -0400 Received: from dhcp-5-188.str.redhat.com (vpn1-6-35.ams2.redhat.com [10.36.6.35]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q6HG0dqn007516; Tue, 17 Jul 2012 12:01:12 -0400 From: Kevin Wolf To: anthony@codemonkey.ws Date: Tue, 17 Jul 2012 18:00:17 +0200 Message-Id: <1342540838-9027-21-git-send-email-kwolf@redhat.com> In-Reply-To: <1342540838-9027-1-git-send-email-kwolf@redhat.com> References: <1342540838-9027-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 20/41] ide: 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 From: Markus Armbruster 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 ide-hd. ide-drive is legacy. ide-cd doesn't have a geometry. Bonus: info qtree now shows the geometry. Signed-off-by: Markus Armbruster Signed-off-by: Kevin Wolf --- hw/ide/core.c | 19 ++++++++++++++----- hw/ide/internal.h | 4 +++- hw/ide/qdev.c | 22 +++++++++++++++++++++- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/hw/ide/core.c b/hw/ide/core.c index f1966e3..bf1ce89 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -1925,16 +1925,16 @@ static const BlockDevOps ide_cd_block_ops = { int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind, const char *version, const char *serial, const char *model, - uint64_t wwn) + uint64_t wwn, + uint32_t cylinders, uint32_t heads, uint32_t secs, + int chs_trans) { - uint32_t cylinders, heads, secs; uint64_t nb_sectors; s->bs = bs; s->drive_kind = kind; bdrv_get_geometry(bs, &nb_sectors); - hd_geometry_guess(bs, &cylinders, &heads, &secs, &s->chs_trans); if (cylinders < 1 || cylinders > 16383) { error_report("cyls must be between 1 and 16383"); return -1; @@ -1950,6 +1950,7 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind, s->cylinders = cylinders; s->heads = heads; s->sectors = secs; + s->chs_trans = chs_trans; s->nb_sectors = nb_sectors; s->wwn = wwn; /* The SMART values should be preserved across power cycles @@ -2076,17 +2077,25 @@ void ide_init2(IDEBus *bus, qemu_irq irq) void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0, DriveInfo *hd1, qemu_irq irq) { - int i; + int i, trans; DriveInfo *dinfo; + uint32_t cyls, heads, secs; for(i = 0; i < 2; i++) { dinfo = i == 0 ? hd0 : hd1; ide_init1(bus, i); if (dinfo) { + cyls = dinfo->cyls; + heads = dinfo->heads; + secs = dinfo->secs; + trans = dinfo->trans; + if (!cyls && !heads && !secs) { + hd_geometry_guess(dinfo->bdrv, &cyls, &heads, &secs, &trans); + } if (ide_init_drive(&bus->ifs[i], dinfo->bdrv, dinfo->media_cd ? IDE_CD : IDE_HD, NULL, *dinfo->serial ? dinfo->serial : NULL, - NULL, 0) < 0) { + NULL, 0, cyls, heads, secs, trans) < 0) { error_report("Can't set up IDE drive %s", dinfo->id); exit(1); } diff --git a/hw/ide/internal.h b/hw/ide/internal.h index 56c718e..685e976 100644 --- a/hw/ide/internal.h +++ b/hw/ide/internal.h @@ -545,7 +545,9 @@ uint32_t ide_data_readl(void *opaque, uint32_t addr); int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind, const char *version, const char *serial, const char *model, - uint64_t wwn); + uint64_t wwn, + uint32_t cylinders, uint32_t heads, uint32_t secs, + int chs_trans); void ide_init2(IDEBus *bus, qemu_irq irq); void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0, DriveInfo *hd1, qemu_irq irq); diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c index 87e0b75..3e297dc 100644 --- a/hw/ide/qdev.c +++ b/hw/ide/qdev.c @@ -21,6 +21,7 @@ #include "qemu-error.h" #include #include "blockdev.h" +#include "hw/block-common.h" #include "sysemu.h" /* --------------------------------- */ @@ -143,6 +144,7 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind) IDEState *s = bus->ifs + dev->unit; const char *serial; DriveInfo *dinfo; + int trans; if (dev->conf.discard_granularity && dev->conf.discard_granularity != 512) { error_report("discard_granularity must be 512 for ide"); @@ -158,8 +160,25 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind) } } + trans = BIOS_ATA_TRANSLATION_AUTO; + 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(dev->conf.bs); + dev->conf.cyls = dinfo->cyls; + dev->conf.heads = dinfo->heads; + dev->conf.secs = dinfo->secs; + trans = dinfo->trans; + } + if (!dev->conf.cyls && !dev->conf.heads && !dev->conf.secs) { + hd_geometry_guess(dev->conf.bs, + &dev->conf.cyls, &dev->conf.heads, &dev->conf.secs, + &trans); + } + if (ide_init_drive(s, dev->conf.bs, kind, - dev->version, serial, dev->model, dev->wwn) < 0) { + dev->version, serial, dev->model, dev->wwn, + dev->conf.cyls, dev->conf.heads, dev->conf.secs, + trans) < 0) { return -1; } @@ -202,6 +221,7 @@ static int ide_drive_initfn(IDEDevice *dev) static Property ide_hd_properties[] = { DEFINE_IDE_DEV_PROPERTIES(), + DEFINE_BLOCK_CHS_PROPERTIES(IDEDrive, dev.conf), DEFINE_PROP_END_OF_LIST(), };