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

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