bug-parted
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH parted 3/5] dasd: cache real_sector_size in linux_probe


From: Hans de Goede
Subject: [PATCH parted 3/5] dasd: cache real_sector_size in linux_probe
Date: Tue, 3 Nov 2009 13:08:58 +0100

dasd_alloc was doing an ioctl to get the real sector size for the dasd
device (we are faking 512 bytes sectors), but when called directly
from ped_disk_new_fresh(), the device is not open causing this to fail.

This patch fixes things by caching the real_sector_size in the linux
arch_specific data and making the dasd label handling use this.
libparted/arch/linux.c(_device_set_sector_size): Cache real sector size.
(_device_set_sector_size, init_dasd, linux_new): Only compile dasd code
on s390 and s390x.
---
 libparted/arch/linux.c  |    7 +++++++
 libparted/labels/dasd.c |   34 +++++++++++-----------------------
 2 files changed, 18 insertions(+), 23 deletions(-)

diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index a87f7e2..d5d3597 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -654,10 +654,13 @@ _device_set_sector_size (PedDevice* dev)
         }
 #endif
 
+#if defined __s390__ || defined __s390x__
         /* Return PED_SECTOR_SIZE_DEFAULT for DASDs. */
         if (dev->type == PED_DEVICE_DASD) {
+                arch_specific->real_sector_size = dev->sector_size;
                 dev->sector_size = PED_SECTOR_SIZE_DEFAULT;
         }
+#endif
 
         if (dev->sector_size != PED_SECTOR_SIZE_DEFAULT) {
                 ped_exception_throw (
@@ -1081,6 +1084,7 @@ error:
         return 0;
 }
 
+#if defined __s390__ || defined __s390x__
 static int
 init_dasd (PedDevice* dev, const char* model_name)
 {
@@ -1136,6 +1140,7 @@ error_close_dev:
 error:
         return 0;
 }
+#endif
 
 static int
 init_generic (PedDevice* dev, const char* model_name)
@@ -1282,10 +1287,12 @@ linux_new (const char* path)
                         goto error_free_arch_specific;
                 break;
 
+#if defined __s390__ || defined __s390x__
         case PED_DEVICE_DASD:
                 if (!init_dasd (dev, _("IBM S390 DASD drive")))
                         goto error_free_arch_specific;
                 break;
+#endif
 
         case PED_DEVICE_VIODASD:
                 if (!init_generic (dev, _("IBM iSeries Virtual DASD")))
diff --git a/libparted/labels/dasd.c b/libparted/labels/dasd.c
index a7df859..37b1f1d 100644
--- a/libparted/labels/dasd.c
+++ b/libparted/labels/dasd.c
@@ -69,7 +69,6 @@ typedef struct {
 } DasdPartitionData;
 
 typedef struct {
-       unsigned int real_sector_size;
        unsigned int format_type;
 } DasdDiskSpecific;
 
@@ -161,18 +160,6 @@ dasd_alloc (const PedDevice* dev)
                return NULL;
        }
 
-       /* because we lie to parted we have to compensate with the
-          real sector size.  Record that now. */
-       if (ioctl(arch_specific->fd, BLKSSZGET,
-                         &disk_specific->real_sector_size) == -1) {
-               ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
-                                                       _("Unable to determine 
the block "
-                                                         "size of this dasd"));
-               free(disk_specific);
-               free(disk);
-               return NULL;
-       }
-
        return disk;
 }
 
@@ -320,7 +307,7 @@ dasd_read (PedDisk* disk)
                end = (long long)(long long) anchor.geo.cylinders
                      * (long long)anchor.geo.heads
                      * (long long)disk->dev->hw_geom.sectors
-                     * (long long)disk_specific->real_sector_size
+                     * (long long)arch_specific->real_sector_size
                      / (long long)disk->dev->sector_size - 1;
                part = ped_partition_new (disk, PED_PARTITION_PROTECTED, NULL, 
start, end);
                if (!part)
@@ -359,11 +346,11 @@ dasd_read (PedDisk* disk)
 
                start = (long long)(long long) p->start_trk
                                * (long long) disk->dev->hw_geom.sectors
-                               * (long long) disk_specific->real_sector_size
+                               * (long long) arch_specific->real_sector_size
                                / (long long) disk->dev->sector_size;
                end   = (long long)((long long) p->end_trk + 1)
                                * (long long) disk->dev->hw_geom.sectors
-                               * (long long) disk_specific->real_sector_size
+                               * (long long) arch_specific->real_sector_size
                                / (long long) disk->dev->sector_size - 1;
                part = ped_partition_new(disk, PED_PARTITION_NORMAL, NULL,
                                          start, end);
@@ -423,11 +410,11 @@ dasd_read (PedDisk* disk)
                if (p->fspace_trk > 0) {
                        start = (long long)((long long) p->end_trk + 1)
                                        * (long long) disk->dev->hw_geom.sectors
-                                       * (long long) 
disk_specific->real_sector_size
+                                       * (long long) 
arch_specific->real_sector_size
                                        / (long long) disk->dev->sector_size;
                        end   = (long long)((long long) p->end_trk + 1 + 
p->fspace_trk)
                                        * (long long) disk->dev->hw_geom.sectors
-                                       * (long long) 
disk_specific->real_sector_size
+                                       * (long long) 
arch_specific->real_sector_size
                                        / (long long) disk->dev->sector_size - 
1;
                        part = ped_partition_new (disk, PED_PARTITION_NORMAL,
                                                   NULL, start, end);
@@ -586,9 +573,9 @@ dasd_write (const PedDisk* disk)
                PDEBUG;
 
                start = part->geom.start * disk->dev->sector_size
-                               / disk_specific->real_sector_size / 
disk->dev->hw_geom.sectors;
+                               / arch_specific->real_sector_size / 
disk->dev->hw_geom.sectors;
                stop = (part->geom.end + 1)
-                          * disk->dev->sector_size / 
disk_specific->real_sector_size
+                          * disk->dev->sector_size / 
arch_specific->real_sector_size
                           / disk->dev->hw_geom.sectors - 1;
 
                PDEBUG;
@@ -734,8 +721,9 @@ static PedAlignment*
 dasd_get_partition_alignment(const PedDisk *disk)
 {
         DasdDiskSpecific* disk_specific = disk->disk_specific;
+        LinuxSpecific *arch_specific = LINUX_SPECIFIC(disk->dev);
         PedSector sector_size =
-                disk_specific->real_sector_size / disk->dev->sector_size;
+                arch_specific->real_sector_size / disk->dev->sector_size;
 
         return ped_alignment_new(0, disk->dev->hw_geom.sectors * sector_size);
 }
@@ -754,7 +742,7 @@ _primary_constraint (PedDisk* disk)
 
        arch_specific = LINUX_SPECIFIC (disk->dev);
        disk_specific = disk->disk_specific;
-       sector_size = disk_specific->real_sector_size / disk->dev->sector_size;
+       sector_size = arch_specific->real_sector_size / disk->dev->sector_size;
 
        if (!ped_alignment_init (&start_align, 0,
                                                         
disk->dev->hw_geom.sectors * sector_size))
@@ -880,7 +868,7 @@ dasd_alloc_metadata (PedDisk* disk)
        else
         /* Mark the start of the disk as metadata. */
                vtoc_end = (FIRST_USABLE_TRK * (long long) 
disk->dev->hw_geom.sectors
-                                  * (long long) disk_specific->real_sector_size
+                                  * (long long) arch_specific->real_sector_size
                                   / (long long) disk->dev->sector_size) - 1;
 
        new_part = ped_partition_new 
(disk,PED_PARTITION_METADATA,NULL,0,vtoc_end);
-- 
1.6.5.1





reply via email to

[Prev in Thread] Current Thread [Next in Thread]