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

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