From patchwork Fri Feb 8 14:52:35 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: elelueck@linux.vnet.ibm.com X-Patchwork-Id: 219172 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 2DE232C008D for ; Sat, 9 Feb 2013 01:54:01 +1100 (EST) Received: from localhost ([::1]:42240 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U3pKx-0002wO-Bo for incoming@patchwork.ozlabs.org; Fri, 08 Feb 2013 09:53:59 -0500 Received: from eggs.gnu.org ([208.118.235.92]:42746) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U3pKN-0001Wj-EQ for qemu-devel@nongnu.org; Fri, 08 Feb 2013 09:53:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U3pKK-0002qT-4P for qemu-devel@nongnu.org; Fri, 08 Feb 2013 09:53:23 -0500 Received: from e06smtp13.uk.ibm.com ([195.75.94.109]:54659) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U3pKJ-0002qK-Qp for qemu-devel@nongnu.org; Fri, 08 Feb 2013 09:53:20 -0500 Received: from /spool/local by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 8 Feb 2013 14:51:56 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 8 Feb 2013 14:51:55 -0000 Received: from d06av12.portsmouth.uk.ibm.com (d06av12.portsmouth.uk.ibm.com [9.149.37.247]) by b06cxnps3074.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r18Er9R829622308 for ; Fri, 8 Feb 2013 14:53:09 GMT Received: from d06av12.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av12.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r18ErDmP007465 for ; Fri, 8 Feb 2013 07:53:17 -0700 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d06av12.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r18Er225006895; Fri, 8 Feb 2013 07:53:12 -0700 From: Einar Lueck To: kwolf@redhat.com, stefanha@gmail.com Date: Fri, 8 Feb 2013 15:52:35 +0100 Message-Id: <1360335155-39413-3-git-send-email-elelueck@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1360335155-39413-1-git-send-email-elelueck@linux.vnet.ibm.com> References: <1360335155-39413-1-git-send-email-elelueck@linux.vnet.ibm.com> X-TM-AS-MML: No x-cbid: 13020814-2966-0000-0000-000006ADCB88 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 195.75.94.109 Cc: aliguori@us.ibm.com, agraf@suse.de, qemu-devel@nongnu.org, borntraeger@de.ibm.com, cornelia.huck@de.ibm.com, pbonzini@redhat.com, Einar Lueck Subject: [Qemu-devel] [PATCH V3 2/2] virtio-block: support auto-sensing of block sizes 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 Virtio-blk does not impose fixed block sizes for access to backing devices. This patch introduces support for auto lookup of the block sizes of the backing block device. This automatic lookup needs to be enabled explicitly. Users may do this by specifying (physical|logical)_block_size=0. Machine types may do this for their defaults, too. To achieve this, a new function blkconf_blocksizes is implemented. If physical or logical block size are zero a corresponding ioctl tries to find an appropriate value. If this does not work, 512 is used. blkconf_blocksizes is therefore only called w/in the virtio-blk context. For s390-virtio, this patch configures auto lookup as default. For virtio-ccw, this is already a default in the existing upstream implementation. Signed-off-by: Einar Lueck --- hw/block-common.c | 23 +++++++++++++++++++++++ hw/block-common.h | 12 +++++++++--- hw/qdev-properties.c | 4 +++- hw/s390x/s390-virtio-bus.c | 2 +- hw/virtio-blk.c | 1 + 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/hw/block-common.c b/hw/block-common.c index d21ec3a..7a040d1 100644 --- a/hw/block-common.c +++ b/hw/block-common.c @@ -10,6 +10,9 @@ #include "sysemu/blockdev.h" #include "hw/block-common.h" #include "qemu/error-report.h" +#ifdef __linux__ +#include +#endif void blkconf_serial(BlockConf *conf, char **serial) { @@ -22,6 +25,26 @@ void blkconf_serial(BlockConf *conf, char **serial) } } +void blkconf_blocksizes(BlockConf *conf) +{ + int block_size; + + if (!conf->physical_block_size) { + if (bdrv_ioctl(conf->bs, BLKPBSZGET, &block_size) == 0) { + conf->physical_block_size = (uint16_t) block_size; + } else { + conf->physical_block_size = BLOCK_PROPERTY_STD_BLKSIZE; + } + } + if (!conf->logical_block_size) { + if (bdrv_ioctl(conf->bs, BLKSSZGET, &block_size) == 0) { + conf->logical_block_size = (uint16_t) block_size; + } else { + conf->logical_block_size = BLOCK_PROPERTY_STD_BLKSIZE; + } + } +} + int blkconf_geometry(BlockConf *conf, int *ptrans, unsigned cyls_max, unsigned heads_max, unsigned secs_max) { diff --git a/hw/block-common.h b/hw/block-common.h index bb808f7..d593128 100644 --- a/hw/block-common.h +++ b/hw/block-common.h @@ -40,18 +40,23 @@ static inline unsigned int get_physical_block_exp(BlockConf *conf) return exp; } -#define DEFINE_BLOCK_PROPERTIES(_state, _conf) \ +#define BLOCK_PROPERTY_STD_BLKSIZE 512 +#define DEFINE_BLOCK_PROPERTIES_EXTENDED(_state, _conf, _blksize) \ DEFINE_PROP_DRIVE("drive", _state, _conf.bs), \ DEFINE_PROP_BLOCKSIZE("logical_block_size", _state, \ - _conf.logical_block_size, 512), \ + _conf.logical_block_size, _blksize), \ DEFINE_PROP_BLOCKSIZE("physical_block_size", _state, \ - _conf.physical_block_size, 512), \ + _conf.physical_block_size, _blksize), \ DEFINE_PROP_UINT16("min_io_size", _state, _conf.min_io_size, 0), \ DEFINE_PROP_UINT32("opt_io_size", _state, _conf.opt_io_size, 0), \ DEFINE_PROP_INT32("bootindex", _state, _conf.bootindex, -1), \ DEFINE_PROP_UINT32("discard_granularity", _state, \ _conf.discard_granularity, 0) +#define DEFINE_BLOCK_PROPERTIES(_state, _conf) \ + DEFINE_BLOCK_PROPERTIES_EXTENDED(_state, _conf, \ + BLOCK_PROPERTY_STD_BLKSIZE) + #define DEFINE_BLOCK_CHS_PROPERTIES(_state, _conf) \ DEFINE_PROP_UINT32("cyls", _state, _conf.cyls, 0), \ DEFINE_PROP_UINT32("heads", _state, _conf.heads, 0), \ @@ -60,6 +65,7 @@ static inline unsigned int get_physical_block_exp(BlockConf *conf) /* Configuration helpers */ void blkconf_serial(BlockConf *conf, char **serial); +void blkconf_blocksizes(BlockConf *conf); int blkconf_geometry(BlockConf *conf, int *trans, unsigned cyls_max, unsigned heads_max, unsigned secs_max); diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c index a8a31f5..73b6da0 100644 --- a/hw/qdev-properties.c +++ b/hw/qdev-properties.c @@ -650,7 +650,9 @@ static void set_blocksize(Object *obj, Visitor *v, void *opaque, error_propagate(errp, local_err); return; } - if (value < min || value > max) { + + /* value == 0 indicates that block size should be sensed later on */ + if ((value < min || value > max) && value > 0) { error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE, dev->id?:"", name, (int64_t)value, min, max); return; diff --git a/hw/s390x/s390-virtio-bus.c b/hw/s390x/s390-virtio-bus.c index d467781..f403308 100644 --- a/hw/s390x/s390-virtio-bus.c +++ b/hw/s390x/s390-virtio-bus.c @@ -426,7 +426,7 @@ static const TypeInfo s390_virtio_net = { }; static Property s390_virtio_blk_properties[] = { - DEFINE_BLOCK_PROPERTIES(VirtIOS390Device, blk.conf), + DEFINE_BLOCK_PROPERTIES_EXTENDED(VirtIOS390Device, blk.conf, 0), DEFINE_BLOCK_CHS_PROPERTIES(VirtIOS390Device, blk.conf), DEFINE_PROP_STRING("serial", VirtIOS390Device, blk.serial), #ifdef __linux__ diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c index 34913ee..cd25712 100644 --- a/hw/virtio-blk.c +++ b/hw/virtio-blk.c @@ -654,6 +654,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk) } blkconf_serial(&blk->conf, &blk->serial); + blkconf_blocksizes(&blk->conf); if (blkconf_geometry(&blk->conf, NULL, 65535, 255, 255) < 0) { return NULL; }