From patchwork Tue Jul 17 16:00:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 171479 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 943CE2C008A for ; Wed, 18 Jul 2012 02:36:17 +1000 (EST) Received: from localhost ([::1]:52129 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SrADy-000860-Tb for incoming@patchwork.ozlabs.org; Tue, 17 Jul 2012 12:02:10 -0400 Received: from eggs.gnu.org ([208.118.235.92]:38398) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SrACz-00079a-W6 for qemu-devel@nongnu.org; Tue, 17 Jul 2012 12:01:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SrACu-0005oK-QK for qemu-devel@nongnu.org; Tue, 17 Jul 2012 12:01:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52403) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SrACu-0005nx-HU for qemu-devel@nongnu.org; Tue, 17 Jul 2012 12:01:04 -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 q6HG12aY019976 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 17 Jul 2012 12:01:02 -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 q6HG0dqg007516; Tue, 17 Jul 2012 12:01:01 -0400 From: Kevin Wolf To: anthony@codemonkey.ws Date: Tue, 17 Jul 2012 18:00:10 +0200 Message-Id: <1342540838-9027-14-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 13/41] hd-geometry: Cut out block layer translation middleman 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 hd_geometry_guess() picks geometry and translation. Callers can get the geometry directly, via parameters, but for translation they need to go through the block layer. Add a parameter for translation, so it can optionally be gotten just like geometry. In preparation of purging translation from the block layer, which will happen later in this series. Signed-off-by: Markus Armbruster Signed-off-by: Kevin Wolf --- hw/block-common.h | 3 ++- hw/hd-geometry.c | 20 ++++++++++++++------ hw/ide/core.c | 2 +- hw/scsi-disk.c | 4 ++-- hw/virtio-blk.c | 2 +- 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/hw/block-common.h b/hw/block-common.h index 3a4d4c6..bba817a 100644 --- a/hw/block-common.h +++ b/hw/block-common.h @@ -16,6 +16,7 @@ /* Hard disk geometry */ void hd_geometry_guess(BlockDriverState *bs, - int *pcyls, int *pheads, int *psecs); + int *pcyls, int *pheads, int *psecs, + int *ptrans); #endif diff --git a/hw/hd-geometry.c b/hw/hd-geometry.c index 241aed9..4d746b7 100644 --- a/hw/hd-geometry.c +++ b/hw/hd-geometry.c @@ -117,7 +117,8 @@ static void guess_chs_for_size(BlockDriverState *bs, } void hd_geometry_guess(BlockDriverState *bs, - int *pcyls, int *pheads, int *psecs) + int *pcyls, int *pheads, int *psecs, + int *ptrans) { int cylinders, heads, secs, translation; @@ -129,6 +130,9 @@ void hd_geometry_guess(BlockDriverState *bs, *pcyls = cylinders; *pheads = heads; *psecs = secs; + if (ptrans) { + *ptrans = translation; + } return; } @@ -142,10 +146,10 @@ void hd_geometry_guess(BlockDriverState *bs, translation was active, so a standard physical disk geometry is OK */ guess_chs_for_size(bs, pcyls, pheads, psecs); - bdrv_set_translation_hint(bs, - *pcyls * *pheads <= 131072 - ? BIOS_ATA_TRANSLATION_LARGE - : BIOS_ATA_TRANSLATION_LBA); + translation = *pcyls * *pheads <= 131072 + ? BIOS_ATA_TRANSLATION_LARGE + : BIOS_ATA_TRANSLATION_LBA; + bdrv_set_translation_hint(bs, translation); } else { /* LCHS guess with heads <= 16: use as physical geometry */ *pcyls = cylinders; @@ -153,7 +157,11 @@ void hd_geometry_guess(BlockDriverState *bs, *psecs = secs; /* disable any translation to be in sync with the logical geometry */ - bdrv_set_translation_hint(bs, BIOS_ATA_TRANSLATION_NONE); + translation = BIOS_ATA_TRANSLATION_NONE; + bdrv_set_translation_hint(bs, translation); + } + if (ptrans) { + *ptrans = translation; } bdrv_set_geometry_hint(bs, *pcyls, *pheads, *psecs); trace_hd_geometry_guess(bs, *pcyls, *pheads, *psecs, translation); diff --git a/hw/ide/core.c b/hw/ide/core.c index 0d1bf10..28f04ad 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -1934,7 +1934,7 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind, s->drive_kind = kind; bdrv_get_geometry(bs, &nb_sectors); - hd_geometry_guess(bs, &cylinders, &heads, &secs); + hd_geometry_guess(bs, &cylinders, &heads, &secs, NULL); if (cylinders < 1 || cylinders > 16383) { error_report("cyls must be between 1 and 16383"); return -1; diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 5339c2e..fc077f5 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -990,7 +990,7 @@ 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); + hd_geometry_guess(bdrv, &cylinders, &heads, &secs, NULL); p[2] = (cylinders >> 16) & 0xff; p[3] = (cylinders >> 8) & 0xff; p[4] = cylinders & 0xff; @@ -1024,7 +1024,7 @@ 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); + hd_geometry_guess(bdrv, &cylinders, &heads, &secs, NULL); p[4] = heads & 0xff; p[5] = secs & 0xff; p[6] = s->qdev.blocksize >> 8; diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c index f16c5ce..d2709a7 100644 --- a/hw/virtio-blk.c +++ b/hw/virtio-blk.c @@ -623,7 +623,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk) s->blk = blk; s->rq = NULL; s->sector_mask = (s->conf->logical_block_size / BDRV_SECTOR_SIZE) - 1; - hd_geometry_guess(s->bs, &cylinders, &heads, &secs); + hd_geometry_guess(s->bs, &cylinders, &heads, &secs, NULL); s->vq = virtio_add_queue(&s->vdev, 128, virtio_blk_handle_output);