Enhance fdasd detection and probing (bsc#935127, fate#320525) OBS-URL: https://build.opensuse.org/request/show/495786 OBS-URL: https://build.opensuse.org/package/show/Base:System/parted?expand=0&rev=127
214 lines
7.5 KiB
Diff
214 lines
7.5 KiB
Diff
From: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
|
|
Date: Thu, 17 Sep 2015 15:33:29 +0200
|
|
Subject: dasd: enhance device probing
|
|
References: fate#320525 / bsc#935127
|
|
Patch-mainline: v3.3
|
|
Git-commit: 834713b5aee1edc004f863231dd489ee3a79f536
|
|
|
|
Probe for all device/transport types as every block device
|
|
could be a DASD on s390.
|
|
|
|
Since the calculation of the minimum and optimum alignment
|
|
is different between DASDs and common fixed block disks
|
|
we need a means other than dev->type == PED_DEVICE_DASD.
|
|
For that purpose a static function _ped_device_like_dasd()
|
|
offering a DASD detection heuristic has been added to
|
|
arch/linux.c.
|
|
|
|
By always providing arch-specific alignment functions the
|
|
need for DASD-specific code could be removed from device.c.
|
|
|
|
Observe fdasd_get_geometry return code for proper error
|
|
handling.
|
|
|
|
Remove the obsolete API check as we no longer require the
|
|
DASD-specific IOCTLs.
|
|
|
|
Signed-off-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
|
|
Acked-by: Stefan Haberland <stefan.haberland@de.ibm.com>
|
|
Signed-off-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
|
|
Signed-off-by: Brian C. Lane <bcl@redhat.com>
|
|
Acked-by: Sebastian Parschauer <sparschauer@suse.de>
|
|
---
|
|
libparted/arch/linux.c | 72 ++++++++++++++++++++++++++++++++++++++++++------
|
|
libparted/device.c | 14 ++-------
|
|
libparted/labels/dasd.c | 18 +++++-------
|
|
3 files changed, 76 insertions(+), 28 deletions(-)
|
|
|
|
--- a/libparted/arch/linux.c
|
|
+++ b/libparted/arch/linux.c
|
|
@@ -814,9 +814,13 @@ _device_set_sector_size (PedDevice* dev)
|
|
#endif
|
|
|
|
#if defined __s390__ || defined __s390x__
|
|
+ /* The real_sector_size is currently needed for DASD layouts,
|
|
+ * so we set it unconditionally. In the long run it should
|
|
+ * be considered to use the dev->phys_sector_size in label/dasd.c.
|
|
+ */
|
|
+ arch_specific->real_sector_size = dev->sector_size;
|
|
/* Return PED_SECTOR_SIZE_DEFAULT for DASDs. */
|
|
if (dev->type == PED_DEVICE_DASD) {
|
|
- arch_specific->real_sector_size = dev->sector_size;
|
|
dev->sector_size = PED_SECTOR_SIZE_DEFAULT;
|
|
}
|
|
#endif
|
|
@@ -3259,6 +3263,60 @@ linux_disk_commit (PedDisk* disk)
|
|
return 1;
|
|
}
|
|
|
|
+#if defined __s390__ || defined __s390x__
|
|
+/**
|
|
+ * Check whether this device could be a DASD
|
|
+ *
|
|
+ * The device probing yields PED_DEVICE_DASD for native DASD transport
|
|
+ * If the block device uses a different transport (e.g. virtio)
|
|
+ * a simplified heuristic (assuming a model 3390 with 4K sectors)
|
|
+ * is applied (only) on s390x systems for this check.
|
|
+ *
|
|
+ * \return 1 if the geometry indicates this could be a DASD
|
|
+ * and 0 otherwise
|
|
+ */
|
|
+static int
|
|
+_ped_device_like_dasd(const PedDevice *dev)
|
|
+{
|
|
+ return (dev->type == PED_DEVICE_DASD)
|
|
+ || (dev->hw_geom.heads == 15
|
|
+ && dev->hw_geom.sectors == 12
|
|
+ && (dev->hw_geom.cylinders
|
|
+ * dev->hw_geom.heads
|
|
+ * dev->hw_geom.sectors
|
|
+ * dev->phys_sector_size
|
|
+ == dev->length * dev->sector_size));
|
|
+}
|
|
+
|
|
+
|
|
+
|
|
+static PedAlignment*
|
|
+s390_get_minimum_alignment(const PedDevice *dev)
|
|
+{
|
|
+#if USE_BLKID
|
|
+ return linux_get_minimum_alignment(dev);
|
|
+#else
|
|
+ return ped_alignment_new(0,
|
|
+ dev->phys_sector_size
|
|
+ / dev->sector_size);
|
|
+#endif
|
|
+}
|
|
+
|
|
+static PedAlignment*
|
|
+s390_get_optimum_alignment(const PedDevice *dev)
|
|
+{
|
|
+ /* DASD needs to use minimum alignment */
|
|
+ if (_ped_device_like_dasd(dev))
|
|
+ return s390_get_minimum_alignment(dev);
|
|
+#if USE_BLKID
|
|
+ return linux_get_optimum_alignment(dev);
|
|
+#else
|
|
+ return NULL;
|
|
+#endif
|
|
+}
|
|
+#endif
|
|
+
|
|
+
|
|
#if USE_BLKID
|
|
static PedAlignment*
|
|
linux_get_minimum_alignment(const PedDevice *dev)
|
|
@@ -3299,15 +3357,10 @@ linux_get_optimum_alignment(const PedDev
|
|
&& PED_DEFAULT_ALIGNMENT % optimal_io == 0)
|
|
|| (!optimal_io && minimum_io
|
|
&& PED_DEFAULT_ALIGNMENT % minimum_io == 0)
|
|
- ) {
|
|
- /* DASD needs to use minimum alignment */
|
|
- if (dev->type == PED_DEVICE_DASD)
|
|
- return linux_get_minimum_alignment(dev);
|
|
-
|
|
+ )
|
|
return ped_alignment_new(
|
|
blkid_topology_get_alignment_offset(tp) / dev->sector_size,
|
|
PED_DEFAULT_ALIGNMENT / dev->sector_size);
|
|
- }
|
|
|
|
/* If optimal_io_size is 0 and we don't meet the other criteria
|
|
for using the device.c default, return the minimum alignment. */
|
|
@@ -3372,7 +3425,10 @@ static PedDeviceArchOps linux_dev_ops =
|
|
sync: linux_sync,
|
|
sync_fast: linux_sync_fast,
|
|
probe_all: linux_probe_all,
|
|
-#if USE_BLKID
|
|
+#if defined __s390__ || defined __s390x__
|
|
+ get_minimum_alignment: s390_get_minimum_alignment,
|
|
+ get_optimum_alignment: s390_get_optimum_alignment,
|
|
+#elif USE_BLKID
|
|
get_minimum_alignment: linux_get_minimum_alignment,
|
|
get_optimum_alignment: linux_get_optimum_alignment,
|
|
wipe_signatures: linux_wipe_signatures,
|
|
--- a/libparted/device.c
|
|
+++ b/libparted/device.c
|
|
@@ -550,16 +550,10 @@ ped_device_get_optimum_alignment(const P
|
|
/* If the arch specific code could not give as an alignment
|
|
return a default value based on the type of device. */
|
|
if (align == NULL) {
|
|
- switch (dev->type) {
|
|
- case PED_DEVICE_DASD:
|
|
- align = ped_device_get_minimum_alignment(dev);
|
|
- break;
|
|
- default:
|
|
- /* Align to a grain of 1MiB (like vista / win7) */
|
|
- align = ped_alignment_new(0,
|
|
- (PED_DEFAULT_ALIGNMENT
|
|
- / dev->sector_size));
|
|
- }
|
|
+ /* Align to a grain of 1MiB (like vista / win7) */
|
|
+ align = ped_alignment_new(0,
|
|
+ (PED_DEFAULT_ALIGNMENT
|
|
+ / dev->sector_size));
|
|
}
|
|
|
|
return align;
|
|
--- a/libparted/labels/dasd.c
|
|
+++ b/libparted/labels/dasd.c
|
|
@@ -224,19 +224,13 @@ dasd_probe (const PedDevice *dev)
|
|
|
|
PED_ASSERT(dev != NULL);
|
|
|
|
- if (!(dev->type == PED_DEVICE_DASD
|
|
- || dev->type == PED_DEVICE_VIODASD
|
|
- || dev->type == PED_DEVICE_FILE))
|
|
- return 0;
|
|
-
|
|
arch_specific = LINUX_SPECIFIC(dev);
|
|
|
|
/* add partition test here */
|
|
fdasd_initialize_anchor(&anchor);
|
|
|
|
- fdasd_get_geometry(dev, &anchor, arch_specific->fd);
|
|
-
|
|
- fdasd_check_api_version(&anchor, arch_specific->fd);
|
|
+ if (fdasd_get_geometry(dev, &anchor, arch_specific->fd) == 0)
|
|
+ goto error_cleanup;
|
|
|
|
/* Labels are required on CDL formatted DASDs. */
|
|
if (fdasd_check_volume(&anchor, arch_specific->fd) &&
|
|
@@ -286,7 +280,9 @@ dasd_read (PedDisk* disk)
|
|
|
|
fdasd_initialize_anchor(&anchor);
|
|
|
|
- fdasd_get_geometry(disk->dev, &anchor, arch_specific->fd);
|
|
+ if (fdasd_get_geometry(disk->dev, &anchor, arch_specific->fd) == 0)
|
|
+ goto error_close_dev;
|
|
+
|
|
disk_specific->label_block = anchor.label_block;
|
|
|
|
if ((anchor.geo.cylinders * anchor.geo.heads) > BIG_DISK_SIZE)
|
|
@@ -645,7 +641,9 @@ dasd_write (const PedDisk* disk)
|
|
|
|
/* initialize the anchor */
|
|
fdasd_initialize_anchor(&anchor);
|
|
- fdasd_get_geometry(disk->dev, &anchor, arch_specific->fd);
|
|
+ if (fdasd_get_geometry(disk->dev, &anchor, arch_specific->fd) == 0)
|
|
+ goto error;
|
|
+
|
|
fdasd_check_volume(&anchor, arch_specific->fd);
|
|
memcpy(anchor.vlabel, &disk_specific->vlabel, sizeof(volume_label_t));
|
|
anchor.vlabel_changed++;
|