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

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