[PATCH 2/2] Ensure request.drive is always a list (#485622)

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

 



The main problem here is that get_partition_by_name() has been
removed from partedUtils.py.  The functionality is now provided
by the getPartitionByPath() method on a parted.Disk object.  The
old function in partedUtils would iterate over the PedDisk
collection and each partition manually, whereas now we have to
call getPartitionByPath() for each parted.Disk we have.

request.drive has been used inconsistently throughout the existing
storage code and only started to show up when I was moving things
from anaconda to pyparted.  What this patch does is ensure that
request.drive on RequestSpec objects is always a list or None.
There are a few other changes in the storage code to handle the
request.drive variable always being a list, but I think it should
be pretty straightforward.
---
 autopart.py     |   43 ++++++++++++++++++++++++++++++-------------
 fsset.py        |   21 +++++++++------------
 partRequests.py |    6 +++++-
 partitions.py   |    2 +-
 4 files changed, 45 insertions(+), 27 deletions(-)

diff --git a/autopart.py b/autopart.py
index 81ed9b6..995bf97 100644
--- a/autopart.py
+++ b/autopart.py
@@ -71,10 +71,13 @@ def bootRequestCheck(req, diskset):
     if not req.device or req.ignoreBootConstraints:
         return PARTITION_SUCCESS
 
+    part = None
+
+    if not hasattr(req, "drive"):
+        return PARTITION_SUCCESS
+
     for drive in req.drive:
         part = diskset.disks[drive].getPartitionByPath("/dev/%s" % req.device)
-        if part:
-            break
 
     if not part:
         return PARTITION_SUCCESS
@@ -734,12 +737,12 @@ def growParts(diskset, requests, newParts):
                 donegrowing = 0
 
                 # get amount of space actually used by current allocation
+                startSize = 0
+
                 for drive in request.drive:
                     part = diskset.disks[drive].getPartitionByPath("/dev/%s" % request.device)
                     if part:
-                        break
-
-                startSize = part.geometry.length
+                        startSize += part.geometry.length
 
                 # compute fraction of freespace which to give to this
                 # request. Weight by original request size
@@ -865,11 +868,20 @@ def setPreexistParts(diskset, requests):
     for request in requests:
         if request.type != REQUEST_PREEXIST:
             continue
-        if not diskset.disks.has_key(request.drive):
-            lvmLog.info("pre-existing partition on non-native disk %s, ignoring" %(request.drive,))
-            continue
-        disk = diskset.disks[request.drive]
-        for part in disk.partitions:
+
+        disks = set()
+        for drive in request.drive:
+            if not diskset.disks.has_key(drive):
+                lvmLog.info("pre-existing partition on non-native disk %s, ignoring" %(drive,))
+                continue
+            disks.add(diskset.disks[drive])
+
+        parts = set()
+        for disk in list(disks):
+            for part in disk.partitions:
+                parts.add(part)
+
+        for part in list(parts):
             if part.geometry.start == request.start and part.geometry.end == request.end:
                 if partedUtils.isEfiSystemPartition(part) and \
                         request.fstype.name == "vfat":
@@ -1020,8 +1032,13 @@ def processPartitioning(diskset, requests, newParts):
         elif request.preexist:
             # we need to keep track of the max size of preexisting partitions
             # FIXME: we should also get the max size for LVs at some point
-            part = diskset.disks[request.drive].getPartitionByPath("/dev/%s" % request.device)
-            request.maxResizeSize = part.getMaxAvailableSize(unit="MB")
+            if request.maxResizeSize is None:
+                request.maxResizeSize = 0
+
+            for drive in request.drive:
+                part = diskset.disks[drive].getPartitionByPath("/dev/%s" % request.device)
+                if part:
+                    request.maxResizeSize += part.getMaxAvailableSize(unit="MB")
 
 ##     print("disk layout after everything is done")
 ##     print(diskset.diskState())
@@ -1264,7 +1281,7 @@ def doAutoPartition(anaconda):
             if (size > 2048):
                 free += size
         for req in partitions.deletes:
-            if isinstance(req, partRequests.DeleteSpec) and req.drive == drive:
+            if isinstance(req, partRequests.DeleteSpec) and (drive in req.drive):
                 size = req.end - req.start
                 # don't count any partition smaller than 1M
                 if (size > 2048):
diff --git a/fsset.py b/fsset.py
index f19603d..fc9af3d 100644
--- a/fsset.py
+++ b/fsset.py
@@ -1658,18 +1658,15 @@ MAILADDR root
             for drive in request.drive:
                 part = diskset.disks[drive].getPartitionByPath("/dev/%s" % bootDev.device.device)
                 if part:
-                    break
-
-            # on EFI systems, *only* /boot/efi should be marked bootable
-            # similarly, on pseries, we really only want the PReP partition
-            # active
-            if iutil.isEfi() \
-                    or iutil.getPPCMachine() in ("pSeries", "iSeries", "PMac") \
-                    or (iutil.isX86() \
-                             and partedUtils.hasGptLabel(diskset, drive)):
-                if part and part.isFlagAvailable(parted.PARTITION_BOOT):
-                    part.setFlag(parted.PARTITION_BOOT)
-                return
+                    # on EFI systems, *only* /boot/efi should be marked bootable
+                    # similarly, on pseries, we really only want the PReP partition
+                    # active
+                    if iutil.isEfi() or \
+                       iutil.getPPCMachine() in ("pSeries", "iSeries", "PMac") or \
+                       (iutil.isX86() and partedUtils.hasGptLabel(diskset, drive)):
+                        if part and part.isFlagAvailable(parted.PARTITION_BOOT):
+                            part.setFlag(parted.PARTITION_BOOT)
+                            return
 
         for drive in diskset.disks.keys():
             foundActive = 0
diff --git a/partRequests.py b/partRequests.py
index d4b41ce..6f95dc4 100644
--- a/partRequests.py
+++ b/partRequests.py
@@ -455,7 +455,11 @@ class PartitionSpec(RequestSpec):
         self.start = start
         self.end = end
 
-        self.drive = drive
+        if (type(drive) != type([])) and (drive is not None):
+            self.drive = [ drive ]
+        else:
+            self.drive = drive
+
         self.primary = primary
         self.multidrive = multidrive
 
diff --git a/partitions.py b/partitions.py
index e95711b..59ad857 100644
--- a/partitions.py
+++ b/partitions.py
@@ -1146,7 +1146,7 @@ class Partitions:
                     self.requests[index] = tmp
                 # for cylinder-based, sort by order on the drive
                 elif (request.start and self.requests[n].start and
-                      (request.drive == self.requests[n].drive) and
+                      (request.drive in self.requests[n].drive) and
                       (request.type == self.requests[n].type) and 
                       (request.start > self.requests[n].start)):
                     tmp = self.requests[n]
-- 
1.6.1.3

_______________________________________________
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