[PATCH 7/9] Create and use a function to obtain a parted alignment for a disk.

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

 



Once the bits are in pyparted this function can be made to actually
retrieve a meaningful alignment.
---
 storage/partitioning.py |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/storage/partitioning.py b/storage/partitioning.py
index 93359a9..9471513 100644
--- a/storage/partitioning.py
+++ b/storage/partitioning.py
@@ -570,6 +570,16 @@ def getBestFreeSpaceRegion(disk, part_type, req_size,
 
     return best_free
 
+def getDiskAlignment(disk):
+    """ Return a minimal alignment for the specified disk.
+
+        Arguments:
+
+            disk -- a parted.Disk instance
+
+    """
+    return parted.Alignment(offset=0, grainSize=1)
+
 def sectorsToSize(sectors, sectorSize):
     """ Convert length in sectors to size in MB.
 
@@ -639,12 +649,21 @@ def addPartition(disk, free, part_type, size):
         Return value is a parted.Partition instance.
 
     """
+    _a = getDiskAlignment(disk)
+    start = free.start
+    if not _a.isAligned(free, start):
+        start = _a.alignNearest(free, start)
+        log.debug("adjusted start sector from %d to %d" % (free.start, start))
+
     if part_type == parted.PARTITION_EXTENDED:
         end = free.end
     else:
         # size is in MB
         length = sizeToSectors(size, disk.device.physicalSectorSize)
         end = start + length
+        if not _a.isAligned(free, end):
+            end = _a.alignNearest(free, end)
+            log.debug("adjusted length from %d to %d" % (length, end - start))
 
     new_geom = parted.Geometry(device=disk.device,
                                start=start,
-- 
1.6.0.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