From patchwork Tue Jul 17 16:00:16 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 171517 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 AFEC82C00B5 for ; Wed, 18 Jul 2012 03:35:20 +1000 (EST) Received: from localhost ([::1]:45850 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SrBg6-0003qJ-Ql for incoming@patchwork.ozlabs.org; Tue, 17 Jul 2012 13:35:18 -0400 Received: from eggs.gnu.org ([208.118.235.92]:38602) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SrADC-0007WF-K6 for qemu-devel@nongnu.org; Tue, 17 Jul 2012 12:01:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SrAD3-0005rk-Bb for qemu-devel@nongnu.org; Tue, 17 Jul 2012 12:01:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47725) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SrAD3-0005rT-3O for qemu-devel@nongnu.org; Tue, 17 Jul 2012 12:01:13 -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 q6HG1BF6020029 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 17 Jul 2012 12:01:11 -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 q6HG0dqm007516; Tue, 17 Jul 2012 12:01:10 -0400 From: Kevin Wolf To: anthony@codemonkey.ws Date: Tue, 17 Jul 2012 18:00:16 +0200 Message-Id: <1342540838-9027-20-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 19/41] virtio-blk: 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=... Bonus: info qtree now shows the geometry. Signed-off-by: Markus Armbruster Signed-off-by: Kevin Wolf --- hw/s390-virtio-bus.c | 1 + hw/virtio-blk.c | 41 ++++++++++++++++++++++++++++++++--------- hw/virtio-pci.c | 1 + 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/hw/s390-virtio-bus.c b/hw/s390-virtio-bus.c index 4d49b96..a245684 100644 --- a/hw/s390-virtio-bus.c +++ b/hw/s390-virtio-bus.c @@ -402,6 +402,7 @@ static TypeInfo s390_virtio_net = { static Property s390_virtio_blk_properties[] = { DEFINE_BLOCK_PROPERTIES(VirtIOS390Device, blk.conf), + DEFINE_BLOCK_CHS_PROPERTIES(VirtIOS390Device, blk.conf), DEFINE_PROP_STRING("serial", VirtIOS390Device, blk.serial), #ifdef __linux__ DEFINE_PROP_BIT("scsi", VirtIOS390Device, blk.scsi, 0, true), diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c index 4344e28..3885904 100644 --- a/hw/virtio-blk.c +++ b/hw/virtio-blk.c @@ -479,19 +479,17 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config) VirtIOBlock *s = to_virtio_blk(vdev); struct virtio_blk_config blkcfg; uint64_t capacity; - int cylinders, heads, secs; int blk_size = s->conf->logical_block_size; bdrv_get_geometry(s->bs, &capacity); - bdrv_get_geometry_hint(s->bs, &cylinders, &heads, &secs); memset(&blkcfg, 0, sizeof(blkcfg)); stq_raw(&blkcfg.capacity, capacity); stl_raw(&blkcfg.seg_max, 128 - 2); - stw_raw(&blkcfg.cylinders, cylinders); + stw_raw(&blkcfg.cylinders, s->conf->cyls); stl_raw(&blkcfg.blk_size, blk_size); stw_raw(&blkcfg.min_io_size, s->conf->min_io_size / blk_size); stw_raw(&blkcfg.opt_io_size, s->conf->opt_io_size / blk_size); - blkcfg.heads = heads; + blkcfg.heads = s->conf->heads; /* * We must ensure that the block device capacity is a multiple of * the logical block size. If that is not the case, lets use @@ -503,10 +501,10 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config) * divided by 512 - instead it is the amount of blk_size blocks * per track (cylinder). */ - if (bdrv_getlength(s->bs) / heads / secs % blk_size) { - blkcfg.sectors = secs & ~s->sector_mask; + if (bdrv_getlength(s->bs) / s->conf->heads / s->conf->secs % blk_size) { + blkcfg.sectors = s->conf->secs & ~s->sector_mask; } else { - blkcfg.sectors = secs; + blkcfg.sectors = s->conf->secs; } blkcfg.size_max = 0; blkcfg.physical_block_exp = get_physical_block_exp(s->conf); @@ -590,7 +588,6 @@ static const BlockDevOps virtio_block_ops = { VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk) { VirtIOBlock *s; - uint32_t cylinders, heads, secs; static int virtio_blk_id; DriveInfo *dinfo; @@ -623,7 +620,33 @@ 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, NULL); + + if (!blk->conf.cyls && !blk->conf.heads && !blk->conf.secs) { + /* try to fall back to value set with legacy -drive cyls=... */ + dinfo = drive_get_by_blockdev(blk->conf.bs); + blk->conf.cyls = dinfo->cyls; + blk->conf.heads = dinfo->heads; + blk->conf.secs = dinfo->secs; + } + if (!blk->conf.cyls && !blk->conf.heads && !blk->conf.secs) { + hd_geometry_guess(s->bs, + &blk->conf.cyls, &blk->conf.heads, &blk->conf.secs, + NULL); + } + if (blk->conf.cyls || blk->conf.heads || blk->conf.secs) { + if (blk->conf.cyls < 1 || blk->conf.cyls > 65535) { + error_report("cyls must be between 1 and 65535"); + return NULL; + } + if (blk->conf.heads < 1 || blk->conf.heads > 255) { + error_report("heads must be between 1 and 255"); + return NULL; + } + if (blk->conf.secs < 1 || blk->conf.secs > 255) { + error_report("secs must be between 1 and 255"); + return NULL; + } + } s->vq = virtio_add_queue(&s->vdev, 128, virtio_blk_handle_output); diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index 9342eed..557d1d3 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -936,6 +936,7 @@ static int virtio_balloon_exit_pci(PCIDevice *pci_dev) static Property virtio_blk_properties[] = { DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0), DEFINE_BLOCK_PROPERTIES(VirtIOPCIProxy, blk.conf), + DEFINE_BLOCK_CHS_PROPERTIES(VirtIOPCIProxy, blk.conf), DEFINE_PROP_STRING("serial", VirtIOPCIProxy, blk.serial), #ifdef __linux__ DEFINE_PROP_BIT("scsi", VirtIOPCIProxy, blk.scsi, 0, true),