[PATCH] Filter out free regions too small for alignment of partitions.

David Lehman dlehman at redhat.com
Fri Sep 26 19:44:03 UTC 2014


Make sure that we don't even look at regions shorter than the alignment
grain size, and that free regions have sufficient length after aligning
the start and end sector before instantiating a DiskChunk.

Related: rhbz#1083687
Resolves: rhbz#1147068
---
 blivet/partitioning.py | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/blivet/partitioning.py b/blivet/partitioning.py
index f35d092..27db850 100644
--- a/blivet/partitioning.py
+++ b/blivet/partitioning.py
@@ -751,14 +751,18 @@ def getFreeRegions(disks):
     """ Return a list of free regions on the specified disks.
 
         :param disks: list of disks
-        :type disks: list of :class:`~.devices.Disks`
+        :type disks: list of :class:`~.devices.Disk`
         :returns: list of free regions
         :rtype: list of :class:`parted.Geometry`
+
+        Only free regions guaranteed to contain at least one aligned sector for
+        both the start and end alignments in the
+        :class:`~.formats.disklabel.DiskLabel` are returned.
     """
     free = []
     for disk in disks:
         for f in disk.format.partedDisk.getFreeSpaceRegions():
-            if f.length > 0:
+            if f.length >= disk.format.alignment.grainSize:
                 free.append(f)
 
     return free
@@ -1704,6 +1708,8 @@ def getDiskChunks(disk, partitions, free):
         :rtype: list of :class:`DiskChunk`
 
         Partitions and free regions not on the specified disk are ignored.
+
+        Chunks contain an aligned version of the free region's geometry.
     """
     # list of all new partitions on this disk
     disk_parts = [p for p in partitions if p.disk == disk and not p.exists]
@@ -1711,10 +1717,18 @@ def getDiskChunks(disk, partitions, free):
 
     chunks = []
     for f in disk_free:
-        # align the geometry so we have a realistic view of the free space
+        # Align the geometry so we have a realistic view of the free space.
+        # alignUp and alignDown can align in the reverse direction if the only
+        # aligned sector within the geometry is in that direction, so we have to
+        # also check that the resulting aligned geometry has a non-zero length.
+        # (It is possible that both will align to the same sector in a small
+        #  enough region.)
         geom = parted.Geometry(device=f.device,
                                start=disk.format.alignment.alignUp(f, f.start),
                                end=disk.format.endAlignment.alignDown(f, f.end))
+        if geom.length < disk.format.alignment.grainSize:
+            continue
+
         chunks.append(DiskChunk(geom))
 
     for p in disk_parts:
-- 
1.9.3



More information about the anaconda-patches mailing list