From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:48619) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SXW8p-0007wp-O6 for qemu-devel@nongnu.org; Thu, 24 May 2012 07:23:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SXW8g-0006Sb-Jk for qemu-devel@nongnu.org; Thu, 24 May 2012 07:23:39 -0400 Received: from e06smtp13.uk.ibm.com ([195.75.94.109]:48263) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SXW8g-0006RR-AL for qemu-devel@nongnu.org; Thu, 24 May 2012 07:23:30 -0400 Received: from /spool/local by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 24 May 2012 12:23:26 +0100 Received: from d06av02.portsmouth.uk.ibm.com (d06av02.portsmouth.uk.ibm.com [9.149.37.228]) by d06nrmr1707.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q4OBN4Qa2256900 for ; Thu, 24 May 2012 12:23:04 +0100 Received: from d06av02.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q4OBN268028144 for ; Thu, 24 May 2012 05:23:03 -0600 From: Christian Borntraeger Date: Thu, 24 May 2012 13:22:55 +0200 Message-Id: <1337858575-37612-2-git-send-email-borntraeger@de.ibm.com> In-Reply-To: <1337858575-37612-1-git-send-email-borntraeger@de.ibm.com> References: <1337858575-37612-1-git-send-email-borntraeger@de.ibm.com> Subject: [Qemu-devel] [PATCH 1/1] Fix geometry sector calculation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: qemu-devel , Alexander Graf , Markus Armbruster , Christian Borntraeger , Stefan Weinhuber , Christoph Hellwig Currently the sector value for the geometry is masked, even if the user usesa command line parameter that explicitely gives a number. This breaks dasd devices on s390. A dasd device can have a physical block size of 4096 (== same for logical block size) and a typcial geometry of 15 heads and 12 sectors per cyl. The ibm partition detection relies on a correct geometry reported by the device. Unfortunately the current code changes 12 to 8. This would be necessary if the total size is not a multiple of logical sector size, but for dasd this is not the case. This patch checks the device size and only applies sector mask if necessary. Signed-off-by: Christian Borntraeger CC: Christoph Hellwig --- hw/virtio-blk.c | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-) diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c index f9e1896..41c5bae 100644 --- a/hw/virtio-blk.c +++ b/hw/virtio-blk.c @@ -489,7 +489,22 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config) 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.sectors = secs & ~s->sector_mask; + /* + * We must ensure that the block device capacity is a multiple of + * the logical block size. If that is not the case, lets use + * sector_mask to adopt the geometry to have a correct picture. + * For those devices where the capacity is ok for the given geometry + * we dont touch the sector value of the geometry, since some devices + * (like s390 dasd) need a specific value. Here the capacity is already + * cyls*heads*secs*blz_size and the sector value is not block size + * 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; + } else { + blkcfg.sectors = secs; + } blkcfg.size_max = 0; blkcfg.physical_block_exp = get_physical_block_exp(s->conf); blkcfg.alignment_offset = 0; -- 1.7.0.4