From patchwork Sat Jun 23 00:33:05 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 166699 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 4FFD5B6FA8 for ; Sat, 23 Jun 2012 10:34:09 +1000 (EST) Received: from localhost ([::1]:53282 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SiEIh-0005SJ-4g for incoming@patchwork.ozlabs.org; Fri, 22 Jun 2012 20:34:07 -0400 Received: from eggs.gnu.org ([208.118.235.92]:53778) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SiEIV-0005Qq-Mk for qemu-devel@nongnu.org; Fri, 22 Jun 2012 20:33:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SiEIT-0007s6-Ok for qemu-devel@nongnu.org; Fri, 22 Jun 2012 20:33:55 -0400 Received: from mail-pz0-f45.google.com ([209.85.210.45]:50139) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SiEIT-0007rl-G1 for qemu-devel@nongnu.org; Fri, 22 Jun 2012 20:33:53 -0400 Received: by mail-pz0-f45.google.com with SMTP id n2so3053134dad.4 for ; Fri, 22 Jun 2012 17:33:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=wB5zIMqEBrCMTL4acBaw/i5cB1KzVqanpbMHX3FlL0k=; b=mhf5UOfhLmneMfDhCS2r8E7l4bIP9eZ+vRYTzxrwQj5rupBqN5JLqT6OnnJMmEokqX 7EG8VBNaiCPBkPYEuj2LY556v3m3sGvNlMPUX2JR1ROsil7shhyEtbr6VHp2fnogZCJq lTtq9xE+cdxBgdROsDzilQHZHb6UKOBJn7xKrXgCRRWFBtP5aJcdC2tqZ9CInmDgrWt+ ZJ4oQZ/19VBMAc2U5UQhNK/MR1wYt2RMoQeH8koOqVBT9ZLqidw0nll4MvuWD9xbJyx9 mvc0nmUmseJLz+v/d7PVMww9g4rlfD/DaExAj4PjziNHpcAeQZWfosvG53i1PhmKTUhi 4t7w== Received: by 10.68.237.103 with SMTP id vb7mr11962564pbc.38.1340411632304; Fri, 22 Jun 2012 17:33:52 -0700 (PDT) Received: from localhost.localdomain ([32.97.110.59]) by mx.google.com with ESMTPS id os1sm630169pbb.49.2012.06.22.17.33.49 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 22 Jun 2012 17:33:51 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Fri, 22 Jun 2012 19:33:05 -0500 Message-Id: <1340411610-22596-2-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1340411610-22596-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1340411610-22596-1-git-send-email-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.210.45 Cc: aliguori@us.ibm.com Subject: [Qemu-devel] [PATCH stable-1.1 01/26] virtio-blk: Fix geometry sector calculation 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: Christian Borntraeger 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 Reviewed-by: Paolo Bonzini Signed-off-by: Kevin Wolf --- 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..4f57450 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*blk_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;