[PATCH 3/9] Use new functions for conversion between size and sector count.

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

 



---
 storage/partitioning.py |   39 ++++++++++++++++++++++++++++-----------
 1 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/storage/partitioning.py b/storage/partitioning.py
index 971dd7d..56c52c5 100644
--- a/storage/partitioning.py
+++ b/storage/partitioning.py
@@ -570,6 +570,26 @@ def getBestFreeSpaceRegion(disk, part_type, req_size,
 
     return best_free
 
+def sectorsToSize(sectors, sectorSize):
+    """ Convert length in sectors to size in MB.
+
+        Arguments:
+
+            sectors     -   sector count
+            sectorSize  -   sector size for the device, in bytes
+    """
+    return (sectors * sectorSize) / (1024.0 * 1024.0)
+
+def sizeToSectors(size, sectorSize):
+    """ Convert size in MB to length in sectors.
+
+        Arguments:
+
+            size        -   size in MB
+            sectorSize  -   sector size for the device, in bytes
+    """
+    return (size * 1024.0 * 1024.0) / sectorSize
+
 def doPartitioning(storage, exclusiveDisks=None):
     """ Allocate and grow partitions.
 
@@ -856,7 +876,7 @@ def allocatePartitions(disks, partitions):
         # create minimum geometry for this request
         # req_size is in MB
         sectors_per_track = disklabel.partedDevice.biosGeometry[2]
-        length = (_part.req_size * (1024 * 1024)) / sectorSize
+        length = sizeToSectors(_part.req_size, sectorSize)
         new_geom = parted.Geometry(device=disklabel.partedDevice,
                                    start=max(sectors_per_track, free.start),
                                    length=length)
@@ -982,9 +1002,9 @@ def growPartitions(disks, partitions):
             limited[id(part)] = False
 
             if part.req_max_size:
-                req_max_sect = (part.req_max_size * (1024 * 1024)) / sectorSize
+                req_max_sect = sizeToSectors(part.req_max_size, sectorSize)
                 if req_max_sect < max_sectors:
-                    mb = ((max_sectors - req_max_sect) * sectorSize) / (1024*1024)
+                    mb = sectorsToSize(max_sectors - req_max_sect, sectorSize)
 
                     log.debug("adding %dMB to leftovers from %s"
                                 % (mb, part.name))
@@ -1004,7 +1024,7 @@ def growPartitions(disks, partitions):
                 leftover_share = float(req_sectors) / float(unlimited_total)
                 max_grow += leftover_share * leftover
             max_sectors = req_sectors + max_grow
-            max_mb = (max_sectors * sectorSize) / (1024 * 1024)
+            max_mb = sectorsToSize(max_sectors, sectorSize)
 
             log.debug("%s: base_size=%dMB, max_size=%sMB" %
                     (part.name, part.req_base_size,  part.req_max_size))
@@ -1018,8 +1038,7 @@ def growPartitions(disks, partitions):
             # don't grow beyond the request's maximum size
             if part.req_max_size:
                 log.debug("max_size: %dMB" % part.req_max_size)
-                # FIXME: round down to nearest cylinder boundary
-                req_max_sect = (part.req_max_size * (1024 * 1024)) / sectorSize
+                req_max_sect = sizeToSectors(part.req_max_size, sectorSize)
                 if req_max_sect < max_sectors:
                     max_grow -= (max_sectors - req_max_sect)
                     max_sectors = req_sectors + max_grow
@@ -1027,8 +1046,7 @@ def growPartitions(disks, partitions):
             # don't grow beyond the resident filesystem's max size
             if part.format.maxSize > 0:
                 log.debug("format maxsize: %dMB" % part.format.maxSize)
-                # FIXME: round down to nearest cylinder boundary
-                fs_max_sect = (part.format.maxSize * (1024 * 1024)) / sectorSize
+                fs_max_sect = sizeToSectors(part.format.maxSize, sectorSize)
                 if fs_max_sect < max_sectors:
                     max_grow -= (max_sectors - fs_max_sect)
                     max_sectors = req_sectors + max_grow
@@ -1037,7 +1055,6 @@ def growPartitions(disks, partitions):
             if free[0].length < max_grow:
                 log.debug("largest free region: %d sectors (%dMB)" %
                         (free[0].length, free[0].getSize()))
-                # FIXME: round down to nearest cylinder boundary
                 max_grow = free[0].length
                 max_sectors = req_sectors + max_grow
 
@@ -1047,7 +1064,7 @@ def growPartitions(disks, partitions):
             # We could call allocatePartitions after modifying this
             # request and saving the original value of part.req_size,
             # or we could try to use disk.maximizePartition().
-            max_size = (max_sectors * sectorSize) / (1024 * 1024)
+            max_size = sectorsToSize(max_sectors, sectorSize)
             orig_size = part.req_size
             # try the max size to begin with
             log.debug("attempting to allocate maximum size: %dMB" % max_size)
@@ -1071,7 +1088,7 @@ def growPartitions(disks, partitions):
                 last_size = part.req_size
                 increment /= 2
                 req_sectors = op_func(req_sectors, increment)
-                part.req_size = (req_sectors * sectorSize) / (1024 * 1024)
+                part.req_size = sectorsToSize(req_sectors, sectorSize)
                 log.debug("attempting size=%dMB" % part.req_size)
                 count += 1
                 try:
-- 
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