[PATCH 4/5] Clean up obsolete extended partitions if partitioning fails.

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

 



If we have an extended partition from a previous run through
doPartitioning and then partitioning fails we have to make sure
that obsolete extended is removed before we return control to
the partition gui.

(cherry picked from commit 242815d89a2d9d3764fabf5b93aedcd9a9df03c2)

Resolves: rhbz#725395
---
 storage/partitioning.py |  105 ++++++++++++++++++++++++----------------------
 1 files changed, 55 insertions(+), 50 deletions(-)

diff --git a/storage/partitioning.py b/storage/partitioning.py
index 42f9a0c..0484eb5 100644
--- a/storage/partitioning.py
+++ b/storage/partitioning.py
@@ -842,6 +842,49 @@ def getFreeRegions(disks):
 
     return free
 
+def updateExtendedPartitions(storage, disks):
+    # XXX hack -- if we created any extended partitions we need to add
+    #             them to the tree now
+    for disk in disks:
+        extended = disk.format.extendedPartition
+        if not extended:
+            # remove any obsolete extended partitions
+            for part in storage.partitions:
+                if part.disk == disk and part.isExtended:
+                    if part.exists:
+                        storage.destroyDevice(part)
+                    else:
+                        storage.devicetree._removeDevice(part, moddisk=False)
+            continue
+
+        extendedName = devicePathToName(extended.getDeviceNodeName())
+        # remove any obsolete extended partitions
+        for part in storage.partitions:
+            if part.disk == disk and part.isExtended and \
+               part.partedPartition not in disk.format.partitions:
+                if part.exists:
+                    storage.destroyDevice(part)
+                else:
+                    storage.devicetree._removeDevice(part, moddisk=False)
+
+        device = storage.devicetree.getDeviceByName(extendedName)
+        if device:
+            if not device.exists:
+                # created by us, update partedPartition
+                device.partedPartition = extended
+            continue
+
+        # This is a little odd because normally instantiating a partition
+        # that does not exist means leaving self.parents empty and instead
+        # populating self.req_disks. In this case, we need to skip past
+        # that since this partition is already defined.
+        device = PartitionDevice(extendedName, parents=disk)
+        device.parents = [disk]
+        device.partedPartition = extended
+        # just add the device for now -- we'll handle actions at the last
+        # moment to simplify things
+        storage.devicetree._addDevice(device)
+
 def doPartitioning(storage, exclusiveDisks=None):
     """ Allocate and grow partitions.
 
@@ -906,59 +949,21 @@ def doPartitioning(storage, exclusiveDisks=None):
 
     removeNewPartitions(disks, partitions)
     free = getFreeRegions(disks)
-    allocatePartitions(storage, disks, partitions, free)
-    growPartitions(disks, partitions, free)
 
-    # The number and thus the name of partitions may have changed now,
-    # allocatePartitions() takes care of this for new partitions, but not
-    # for pre-existing ones, so we update the name of all partitions here
-    for part in storage.partitions:
-        # needed because of XXX hack below
-        if part.isExtended:
-            continue
-        part.updateName()
-
-    # XXX hack -- if we created any extended partitions we need to add
-    #             them to the tree now
-    for disk in disks:
-        extended = disk.format.extendedPartition
-        if not extended:
-            # remove any obsolete extended partitions
-            for part in storage.partitions:
-                if part.disk == disk and part.isExtended:
-                    if part.exists:
-                        storage.destroyDevice(part)
-                    else:
-                        storage.devicetree._removeDevice(part, moddisk=False)
-            continue
-
-        extendedName = devicePathToName(extended.getDeviceNodeName())
-        # remove any obsolete extended partitions
+    try:
+        allocatePartitions(storage, disks, partitions, free)
+        growPartitions(disks, partitions, free)
+    finally:
+        # The number and thus the name of partitions may have changed now,
+        # allocatePartitions() takes care of this for new partitions, but not
+        # for pre-existing ones, so we update the name of all partitions here
         for part in storage.partitions:
-            if part.disk == disk and part.isExtended and \
-               part.partedPartition not in disk.format.partitions:
-                if part.exists:
-                    storage.destroyDevice(part)
-                else:
-                    storage.devicetree._removeDevice(part, moddisk=False)
-
-        device = storage.devicetree.getDeviceByName(extendedName)
-        if device:
-            if not device.exists:
-                # created by us, update partedPartition
-                device.partedPartition = extended
-            continue
+            # leave extended partitions as-is -- we'll handle them separately
+            if part.isExtended:
+                continue
+            part.updateName()
 
-        # This is a little odd because normally instantiating a partition
-        # that does not exist means leaving self.parents empty and instead
-        # populating self.req_disks. In this case, we need to skip past
-        # that since this partition is already defined.
-        device = PartitionDevice(extendedName, parents=disk)
-        device.parents = [disk]
-        device.partedPartition = extended
-        # just add the device for now -- we'll handle actions at the last
-        # moment to simplify things
-        storage.devicetree._addDevice(device)
+        updateExtendedPartitions(storage, disks)
 
 def allocatePartitions(storage, disks, partitions, freespace):
     """ Allocate partitions based on requested features.
-- 
1.7.7.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