Received: from eggs.gnu.org ([2001:4830:134:3::10]:37819) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XC6VL-0005S5-Ax for qemu-devel@nongnu.org; Tue, 29 Jul 2014 08:27:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XC6V6-00067O-Qw for qemu-devel@nongnu.org; Tue, 29 Jul 2014 08:27:43 -0400 Received: from e06smtp11.uk.ibm.com ([195.75.94.107]:36827) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XC6V6-00067D-IE for qemu-devel@nongnu.org; Tue, 29 Jul 2014 08:27:28 -0400 Received: from /spool/local by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 29 Jul 2014 13:27:27 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id D71F917D8056 for ; Tue, 29 Jul 2014 13:29:07 +0100 (BST) Received: from d06av01.portsmouth.uk.ibm.com (d06av01.portsmouth.uk.ibm.com [9.149.37.212]) by b06cxnps4075.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s6TCRP2Z36372598 for ; Tue, 29 Jul 2014 12:27:25 GMT Received: from d06av01.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av01.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s6TCROs8005622 for ; Tue, 29 Jul 2014 06:27:25 -0600 From: Ekaterina Tumanova Date: Tue, 29 Jul 2014 14:27:16 +0200 Message-Id: <1406636839-11946-2-git-send-email-tumanova@linux.vnet.ibm.com> In-Reply-To: <1406636839-11946-1-git-send-email-tumanova@linux.vnet.ibm.com> References: <1406636839-11946-1-git-send-email-tumanova@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 1/4] hd-geometry.c: Integrate HDIO_GETGEO in guessing for target-s390x List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Public KVM Mailing List Cc: cornelia.huck@de.ibm.com, dahi@linux.vnet.ibm.com, Ekaterina Tumanova , borntraeger@de.ibm.com This patch extends the function hd_geometry_guess. It introduces a target specific hook. The default implementation for this target specific hook is empty, has therefore no effect and the existing logic works as before. For target-s390x, the behaviour is chosen as follows: If no geo could be guessed via guess_disk_lchs, a new function called guess_disk_pchs is called. The latter utilizes HDIO_GET_GEO ioctl to ask the underlying disk for geometry. If this is not successful (e.g. image files) geometry is derived from the size of the disk (as before). The new HDIO_GETGEO logic is required for two use cases: a) Support for geometries of Direct Attached Storage Disks (DASD) on s390x configured as backing of virtio block devices. b) Support for FCP attached SCSI disks that do not yet have a partition table. Without this patch, fdisk -l on the host would return different results then fdisk -l in the guest. Based on 2013 patch from Einar Lueck Signed-off-by: Ekaterina Tumanova Reviewed-by: David Hildenbrand Acked-by: Cornelia Huck --- hw/block/Makefile.objs | 6 +++++- hw/block/hd-geometry.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/hw/block/Makefile.objs b/hw/block/Makefile.objs index bf46f03..e4f6205 100644 --- a/hw/block/Makefile.objs +++ b/hw/block/Makefile.objs @@ -1,4 +1,4 @@ -common-obj-y += block.o cdrom.o hd-geometry.o +common-obj-y += block.o cdrom.o common-obj-$(CONFIG_FDC) += fdc.o common-obj-$(CONFIG_SSI_M25P80) += m25p80.o common-obj-$(CONFIG_NAND) += nand.o @@ -13,3 +13,7 @@ obj-$(CONFIG_SH4) += tc58128.o obj-$(CONFIG_VIRTIO) += virtio-blk.o obj-$(CONFIG_VIRTIO_BLK_DATA_PLANE) += dataplane/ + +# geometry is target/architecture dependent and therefore needs to be built +# for every target platform +obj-y += hd-geometry.o diff --git a/hw/block/hd-geometry.c b/hw/block/hd-geometry.c index 6feb4f8..7988264 100644 --- a/hw/block/hd-geometry.c +++ b/hw/block/hd-geometry.c @@ -33,6 +33,10 @@ #include "block/block.h" #include "hw/block/block.h" #include "trace.h" +#ifdef __linux__ +#include +#include +#endif struct partition { uint8_t boot_ind; /* 0x80 - active */ @@ -47,6 +51,37 @@ struct partition { uint32_t nr_sects; /* nr of sectors in partition */ } QEMU_PACKED; +static void guess_chs_for_size(BlockDriverState *bs, uint32_t *pcyls, + uint32_t *pheads, uint32_t *psecs); + +/* try to get geometry from disk via HDIO_GETGEO ioctl + Return 0 if OK, -1 if ioctl does not work (e.g. image file) */ +static inline int guess_disk_pchs(BlockDriverState *bs, uint32_t *pcylinders, + uint32_t *pheads, uint32_t *psectors) +{ +#ifdef __linux__ + struct hd_geometry geo; + + if (bdrv_ioctl(bs, HDIO_GETGEO, &geo)) { + return -1; + } + + /* HDIO_GETGEO may return success even though geo contains zeros + (e.g. certain multipath setups) */ + if (!geo.heads || !geo.sectors || !geo.cylinders) { + return -1; + } + + *pheads = geo.heads; + *psectors = geo.sectors; + *pcylinders = geo.cylinders; + return 0; +#else + return -1; +#endif +} + + /* try to guess the disk logical geometry from the MSDOS partition table. Return 0 if OK, -1 if could not guess */ static int guess_disk_lchs(BlockDriverState *bs, @@ -116,6 +151,26 @@ static void guess_chs_for_size(BlockDriverState *bs, *psecs = 63; } +#ifdef TARGET_S390X +void hd_geometry_guess(BlockDriverState *bs, uint32_t *pcyls, uint32_t *pheads, + uint32_t *psecs, int *ptrans) +{ + if (guess_disk_lchs(bs, (int *)pcyls, (int *)pheads, (int *)psecs) == 0) { + goto done; + } + if (guess_disk_pchs(bs, pcyls, pheads, psecs) == 0) { + goto done; + } + /* still no geometry - try to guess from disk size */ + guess_chs_for_size(bs, pcyls, pheads, psecs); +done: + if (ptrans) { + *ptrans = BIOS_ATA_TRANSLATION_NONE; + } + trace_hd_geometry_guess(bs, *pcyls, *pheads, *psecs, + BIOS_ATA_TRANSLATION_NONE); +} +#else void hd_geometry_guess(BlockDriverState *bs, uint32_t *pcyls, uint32_t *pheads, uint32_t *psecs, int *ptrans) @@ -148,6 +203,7 @@ void hd_geometry_guess(BlockDriverState *bs, } trace_hd_geometry_guess(bs, *pcyls, *pheads, *psecs, translation); } +#endif int hd_bios_chs_auto_trans(uint32_t cyls, uint32_t heads, uint32_t secs) { -- 1.8.5.5