From: Ekaterina Tumanova <tumanova@linux.vnet.ibm.com>
To: Public KVM Mailing List <qemu-devel@nongnu.org>
Cc: cornelia.huck@de.ibm.com, dahi@linux.vnet.ibm.com,
Ekaterina Tumanova <tumanova@linux.vnet.ibm.com>,
borntraeger@de.ibm.com
Subject: [Qemu-devel] [PATCH 1/4] hd-geometry.c: Integrate HDIO_GETGEO in guessing for target-s390x
Date: Tue, 29 Jul 2014 14:27:16 +0200 [thread overview]
Message-ID: <1406636839-11946-2-git-send-email-tumanova@linux.vnet.ibm.com> (raw)
In-Reply-To: <1406636839-11946-1-git-send-email-tumanova@linux.vnet.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 <elelueck@de.ibm.com>
Signed-off-by: Ekaterina Tumanova <tumanova@linux.vnet.ibm.com>
Reviewed-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
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 <linux/fs.h>
+#include <linux/hdreg.h>
+#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
next prev parent reply other threads:[~2014-07-29 12:27 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-29 12:27 [Qemu-devel] [PATCH 0/4] Geometry and blocksize support for backing devices Ekaterina Tumanova
2014-07-29 12:27 ` Ekaterina Tumanova [this message]
2014-08-20 8:19 ` [Qemu-devel] [PATCH 1/4] hd-geometry.c: Integrate HDIO_GETGEO in guessing for target-s390x Paolo Bonzini
2014-08-20 9:35 ` Christian Borntraeger
2014-08-20 13:10 ` Paolo Bonzini
2014-08-25 8:21 ` Christian Borntraeger
2014-07-29 12:27 ` [Qemu-devel] [PATCH 2/4] blocksize: support auto-sensing of blocksizes Ekaterina Tumanova
2014-09-03 15:37 ` Stefan Hajnoczi
2014-07-29 12:27 ` [Qemu-devel] [PATCH 3/4] blocksize: Add driver method to get the blocksizes Ekaterina Tumanova
2014-07-29 12:27 ` [Qemu-devel] [PATCH 4/4] blocksize: add blkconf_blocksize call to all block devices Ekaterina Tumanova
2014-09-03 15:46 ` Stefan Hajnoczi
2014-09-04 10:28 ` Ekaterina Tumanova
2014-09-17 14:00 ` Stefan Hajnoczi
2014-09-04 14:15 ` Christian Borntraeger
2014-09-17 13:56 ` Stefan Hajnoczi
2014-07-29 12:37 ` [Qemu-devel] [PATCH 0/4] Geometry and blocksize support for backing devices Christian Borntraeger
2014-11-06 15:58 ` [Qemu-devel] " Christian Borntraeger
2014-11-06 17:24 ` Paolo Bonzini
2014-11-06 19:05 ` Christian Borntraeger
2014-11-07 9:17 ` Markus Armbruster
2014-11-07 9:48 ` Christian Borntraeger
2014-11-07 15:58 ` Markus Armbruster
2014-11-07 13:39 ` Ekaterina Tumanova
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1406636839-11946-2-git-send-email-tumanova@linux.vnet.ibm.com \
--to=tumanova@linux.vnet.ibm.com \
--cc=borntraeger@de.ibm.com \
--cc=cornelia.huck@de.ibm.com \
--cc=dahi@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).