Blame SOURCES/0052-dasd-enhance-device-probing.patch

fc4a62
From 75958b299ed01eadbbcf1df31dacacfcaf8bc13a Mon Sep 17 00:00:00 2001
fc4a62
From: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
fc4a62
Date: Thu, 17 Sep 2015 15:33:29 +0200
fc4a62
Subject: [PATCH 52/54] dasd: enhance device probing
fc4a62
fc4a62
Probe for all device/transport types as every block device
fc4a62
could be a DASD on s390.
fc4a62
fc4a62
Since the calculation of the minimum and optimum alignment
fc4a62
is different between DASDs and common fixed block disks
fc4a62
we need a means other than dev->type == PED_DEVICE_DASD.
fc4a62
For that purpose a static function _ped_device_like_dasd()
fc4a62
offering a DASD detection heuristic has been added to
fc4a62
arch/linux.c.
fc4a62
fc4a62
By always providing arch-specific alignment functions the
fc4a62
need for DASD-specific code could be removed from device.c.
fc4a62
fc4a62
Observe fdasd_get_geometry return code for proper error
fc4a62
handling.
fc4a62
fc4a62
Remove the obsolete API check as we no longer require the
fc4a62
DASD-specific IOCTLs.
fc4a62
fc4a62
Signed-off-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
fc4a62
Acked-by: Stefan Haberland <stefan.haberland@de.ibm.com>
fc4a62
Signed-off-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
fc4a62
Signed-off-by: Brian C. Lane <bcl@redhat.com>
fc4a62
fc4a62
(cherry picked from commit 834713b5aee1edc004f863231dd489ee3a79f536)
fc4a62
fc4a62
Related: rhbz#1676604
fc4a62
---
fc4a62
 libparted/arch/linux.c  | 85 +++++++++++++++++++++++++++++++++--------
fc4a62
 libparted/device.c      | 14 ++-----
fc4a62
 libparted/labels/dasd.c | 18 ++++-----
fc4a62
 3 files changed, 82 insertions(+), 35 deletions(-)
fc4a62
fc4a62
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
fc4a62
index 6e78faf..56cfe6f 100644
fc4a62
--- a/libparted/arch/linux.c
fc4a62
+++ b/libparted/arch/linux.c
fc4a62
@@ -727,9 +727,13 @@ _device_set_sector_size (PedDevice* dev)
fc4a62
 #endif
fc4a62
 
fc4a62
 #if defined __s390__ || defined __s390x__
fc4a62
+        /* The real_sector_size is currently needed for DASD layouts,
fc4a62
+         * so we set it unconditionally. In the long run it should
fc4a62
+         * be considered to use the dev->phys_sector_size in label/dasd.c.
fc4a62
+         */
fc4a62
+        arch_specific->real_sector_size = dev->sector_size;
fc4a62
         /* Return PED_SECTOR_SIZE_DEFAULT for DASDs. */
fc4a62
         if (dev->type == PED_DEVICE_DASD) {
fc4a62
-                arch_specific->real_sector_size = dev->sector_size;
fc4a62
                 dev->sector_size = PED_SECTOR_SIZE_DEFAULT;
fc4a62
         }
fc4a62
 #endif
fc4a62
@@ -3112,19 +3116,72 @@ linux_disk_commit (PedDisk* disk)
fc4a62
 {
fc4a62
         if (disk->dev->type != PED_DEVICE_FILE) {
fc4a62
 
fc4a62
-		/* We now require BLKPG support.  If this assertion fails,
fc4a62
-		   please write to the mailing list describing your system.
fc4a62
-		   Assuming it's never triggered, ...
fc4a62
-		   FIXME: remove this assertion in 2012.  */
fc4a62
-		assert (_have_blkpg ());
fc4a62
+                /* We now require BLKPG support.  If this assertion fails,
fc4a62
+                   please write to the mailing list describing your system.
fc4a62
+                   Assuming it's never triggered, ...
fc4a62
+                   FIXME: remove this assertion in 2012.  */
fc4a62
+                assert (_have_blkpg ());
fc4a62
 
fc4a62
-		if (!_disk_sync_part_table (disk))
fc4a62
-			return 0;
fc4a62
+                if (!_disk_sync_part_table (disk))
fc4a62
+                        return 0;
fc4a62
         }
fc4a62
 
fc4a62
         return 1;
fc4a62
 }
fc4a62
 
fc4a62
+#if defined __s390__ || defined __s390x__
fc4a62
+/**
fc4a62
+ * Check whether this device could be a DASD
fc4a62
+ *
fc4a62
+ * The device probing yields PED_DEVICE_DASD for native DASD transport
fc4a62
+ * If the block device uses a different transport (e.g. virtio)
fc4a62
+ * a simplified heuristic (assuming a model 3390 with 4K sectors)
fc4a62
+ * is applied (only) on s390x systems for this check.
fc4a62
+ *
fc4a62
+ * \return 1 if the geometry indicates this could be a DASD
fc4a62
+ *         and 0 otherwise
fc4a62
+ */
fc4a62
+static int
fc4a62
+_ped_device_like_dasd(const PedDevice *dev)
fc4a62
+{
fc4a62
+        return (dev->type == PED_DEVICE_DASD)
fc4a62
+          || (dev->hw_geom.heads == 15
fc4a62
+              && dev->hw_geom.sectors == 12
fc4a62
+              && (dev->hw_geom.cylinders
fc4a62
+                  * dev->hw_geom.heads
fc4a62
+                  * dev->hw_geom.sectors
fc4a62
+                  * dev->phys_sector_size
fc4a62
+                  == dev->length * dev->sector_size));
fc4a62
+}
fc4a62
+
fc4a62
+
fc4a62
+
fc4a62
+static PedAlignment*
fc4a62
+s390_get_minimum_alignment(const PedDevice *dev)
fc4a62
+{
fc4a62
+#if USE_BLKID
fc4a62
+        return linux_get_minimum_alignment(dev);
fc4a62
+#else
fc4a62
+        return ped_alignment_new(0,
fc4a62
+                                 dev->phys_sector_size
fc4a62
+                                 / dev->sector_size);
fc4a62
+#endif
fc4a62
+}
fc4a62
+
fc4a62
+static PedAlignment*
fc4a62
+s390_get_optimum_alignment(const PedDevice *dev)
fc4a62
+{
fc4a62
+        /* DASD needs to use minimum alignment */
fc4a62
+        if (_ped_device_like_dasd(dev))
fc4a62
+                return s390_get_minimum_alignment(dev);
fc4a62
+#if USE_BLKID
fc4a62
+        return linux_get_optimum_alignment(dev);
fc4a62
+#else
fc4a62
+        return NULL;
fc4a62
+#endif
fc4a62
+}
fc4a62
+#endif
fc4a62
+
fc4a62
 #if USE_BLKID
fc4a62
 static PedAlignment*
fc4a62
 linux_get_minimum_alignment(const PedDevice *dev)
fc4a62
@@ -3165,15 +3222,10 @@ linux_get_optimum_alignment(const PedDevice *dev)
fc4a62
 		&& PED_DEFAULT_ALIGNMENT % optimal_io == 0)
fc4a62
 	    || (!optimal_io && minimum_io
fc4a62
 		&& PED_DEFAULT_ALIGNMENT % minimum_io == 0)
fc4a62
-           ) {
fc4a62
-            /* DASD needs to use minimum alignment */
fc4a62
-            if (dev->type == PED_DEVICE_DASD)
fc4a62
-                return linux_get_minimum_alignment(dev);
fc4a62
-
fc4a62
+           )
fc4a62
             return ped_alignment_new(
fc4a62
                     blkid_topology_get_alignment_offset(tp) / dev->sector_size,
fc4a62
                     PED_DEFAULT_ALIGNMENT / dev->sector_size);
fc4a62
-        }
fc4a62
 
fc4a62
         /* If optimal_io_size is 0 and we don't meet the other criteria
fc4a62
            for using the device.c default, return the minimum alignment. */
fc4a62
@@ -3200,7 +3252,10 @@ static PedDeviceArchOps linux_dev_ops = {
fc4a62
         sync:           linux_sync,
fc4a62
         sync_fast:      linux_sync_fast,
fc4a62
         probe_all:      linux_probe_all,
fc4a62
-#if USE_BLKID
fc4a62
+#if defined __s390__ || defined __s390x__
fc4a62
+        get_minimum_alignment:	s390_get_minimum_alignment,
fc4a62
+        get_optimum_alignment:	s390_get_optimum_alignment,
fc4a62
+#elif USE_BLKID
fc4a62
         get_minimum_alignment:	linux_get_minimum_alignment,
fc4a62
         get_optimum_alignment:	linux_get_optimum_alignment,
fc4a62
 #endif
fc4a62
diff --git a/libparted/device.c b/libparted/device.c
fc4a62
index cdcc117..36fecd2 100644
fc4a62
--- a/libparted/device.c
fc4a62
+++ b/libparted/device.c
fc4a62
@@ -550,16 +550,10 @@ ped_device_get_optimum_alignment(const PedDevice *dev)
fc4a62
         /* If the arch specific code could not give as an alignment
fc4a62
            return a default value based on the type of device. */
fc4a62
         if (align == NULL) {
fc4a62
-                switch (dev->type) {
fc4a62
-                case PED_DEVICE_DASD:
fc4a62
-                        align = ped_device_get_minimum_alignment(dev);
fc4a62
-                        break;
fc4a62
-                default:
fc4a62
-                        /* Align to a grain of 1MiB (like vista / win7) */
fc4a62
-                        align = ped_alignment_new(0,
fc4a62
-                                                  (PED_DEFAULT_ALIGNMENT
fc4a62
-						   / dev->sector_size));
fc4a62
-                }
fc4a62
+                /* Align to a grain of 1MiB (like vista / win7) */
fc4a62
+                align = ped_alignment_new(0,
fc4a62
+                                          (PED_DEFAULT_ALIGNMENT
fc4a62
+                                           / dev->sector_size));
fc4a62
         }
fc4a62
 
fc4a62
         return align;
fc4a62
diff --git a/libparted/labels/dasd.c b/libparted/labels/dasd.c
fc4a62
index 5bffda7..a4be1fd 100644
fc4a62
--- a/libparted/labels/dasd.c
fc4a62
+++ b/libparted/labels/dasd.c
fc4a62
@@ -214,19 +214,13 @@ dasd_probe (const PedDevice *dev)
fc4a62
 
fc4a62
 	PED_ASSERT(dev != NULL);
fc4a62
 
fc4a62
-	if (!(dev->type == PED_DEVICE_DASD
fc4a62
-              || dev->type == PED_DEVICE_VIODASD
fc4a62
-              || dev->type == PED_DEVICE_FILE))
fc4a62
-		return 0;
fc4a62
-
fc4a62
 	arch_specific = LINUX_SPECIFIC(dev);
fc4a62
 
fc4a62
 	/* add partition test here */
fc4a62
 	fdasd_initialize_anchor(&anchor);
fc4a62
 
fc4a62
-	fdasd_get_geometry(dev, &anchor, arch_specific->fd);
fc4a62
-
fc4a62
-	fdasd_check_api_version(&anchor, arch_specific->fd);
fc4a62
+	if (fdasd_get_geometry(dev, &anchor, arch_specific->fd) == 0)
fc4a62
+                goto error_cleanup;
fc4a62
 
fc4a62
 	/* Labels are required on CDL formatted DASDs. */
fc4a62
 	if (fdasd_check_volume(&anchor, arch_specific->fd) &&
fc4a62
@@ -276,7 +270,9 @@ dasd_read (PedDisk* disk)
fc4a62
 
fc4a62
 	fdasd_initialize_anchor(&anchor);
fc4a62
 
fc4a62
-	fdasd_get_geometry(disk->dev, &anchor, arch_specific->fd);
fc4a62
+	if (fdasd_get_geometry(disk->dev, &anchor, arch_specific->fd) == 0)
fc4a62
+                goto error_close_dev;
fc4a62
+
fc4a62
 	disk_specific->label_block = anchor.label_block;
fc4a62
 
fc4a62
 	if ((anchor.geo.cylinders * anchor.geo.heads) > BIG_DISK_SIZE)
fc4a62
@@ -630,7 +626,9 @@ dasd_write (const PedDisk* disk)
fc4a62
 
fc4a62
 	/* initialize the anchor */
fc4a62
 	fdasd_initialize_anchor(&anchor);
fc4a62
-	fdasd_get_geometry(disk->dev, &anchor, arch_specific->fd);
fc4a62
+	if (fdasd_get_geometry(disk->dev, &anchor, arch_specific->fd) == 0)
fc4a62
+                goto error;
fc4a62
+
fc4a62
 	fdasd_check_volume(&anchor, arch_specific->fd);
fc4a62
 	memcpy(anchor.vlabel, &disk_specific->vlabel, sizeof(volume_label_t));
fc4a62
 	anchor.vlabel_changed++;
fc4a62
-- 
fc4a62
2.20.1
fc4a62