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

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