[PATCH] Fixup partition aligning (related #559639)

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

 



Our partitioning code was assuming that having a partition from
sector 0 - 512 means the partition stops at sector 512, iow that
it goes from sector 0 till 511, but that is not how parted geometries
work, the range includes the end sector. So 0 - 512 will get you
a 513 sectors partition.

This patch adds an endAligment property to disklabel which can be used
to properly align end sectors (which must be aligned to the disklabel's
alignment with the offset decreased by 1), patches partitioning.py to
use this to align end sectors and fixes up end sector calculations in
partitioning.py to be start + length - 1.
---
 storage/formats/disklabel.py |   10 ++++++++++
 storage/partitioning.py      |   18 +++++++++---------
 2 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/storage/formats/disklabel.py b/storage/formats/disklabel.py
index 8d278b2..f49e3c1 100644
--- a/storage/formats/disklabel.py
+++ b/storage/formats/disklabel.py
@@ -63,6 +63,7 @@ class DiskLabel(DeviceFormat):
         self._partedDisk = None
         self._origPartedDisk = None
         self._alignment = None
+        self._endAlignment = None
 
         if self.partedDevice:
             # set up the parted objects and raise exception on failure
@@ -339,5 +340,14 @@ class DiskLabel(DeviceFormat):
 
         return self._alignment
 
+    @property
+    def endAlignment(self):
+        if not self._endAlignment:
+            self._endAlignment = parted.Alignment(
+                                        offset = self.alignment.offset - 1,
+                                        grainSize = self.alignment.grainSize)
+
+        return self._endAlignment
+
 register_device_format(DiskLabel)
 
diff --git a/storage/partitioning.py b/storage/partitioning.py
index d912db9..d548cdb 100644
--- a/storage/partitioning.py
+++ b/storage/partitioning.py
@@ -692,10 +692,10 @@ def addPartition(disklabel, free, part_type, size):
     else:
         # size is in MB
         length = sizeToSectors(size, disklabel.partedDevice.sectorSize)
-        end = start + length
-        if not disklabel.alignment.isAligned(free, end):
-            end = disklabel.alignment.alignNearest(free, end)
-            log.debug("adjusted length from %d to %d" % (length, end - start))
+        end = start + length - 1
+        if not disklabel.endAlignment.isAligned(free, end):
+            end = disklabel.endAlignment.alignNearest(free, end)
+            log.debug("adjusted length from %d to %d" % (length, end - start + 1))
 
     new_geom = parted.Geometry(device=disklabel.partedDevice,
                                start=start,
@@ -727,8 +727,8 @@ def getFreeRegions(disks):
             if not disk.format.alignment.isAligned(f, f.start):
                 f.start = disk.format.alignment.alignNearest(f, f.start)
 
-            if not disk.format.alignment.isAligned(f, f.end):
-                f.end = disk.format.alignment.alignNearest(f, f.end)
+            if not disk.format.endAlignment.isAligned(f, f.end):
+                f.end = disk.format.endAlignment.alignNearest(f, f.end)
 
             if f.length > 0:
                 free.append(f)
@@ -1402,10 +1402,10 @@ def growPartitions(disks, partitions, free):
 
                 old_geometry = p.partition.partedPartition.geometry
                 new_length = p.base + p.growth
-                end = start + new_length
+                end = start + new_length - 1
                 # align end sector as needed
-                if not disklabel.alignment.isAligned(chunk.geometry, end):
-                    end = disklabel.alignment.alignDown(chunk.geometry, end)
+                if not disklabel.endAlignment.isAligned(chunk.geometry, end):
+                    end = disklabel.endAlignment.alignDown(chunk.geometry, end)
                 new_geometry = parted.Geometry(device=disklabel.partedDevice,
                                                start=start,
                                                end=end)
-- 
1.6.6

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux