[master 11/11] Move recursiveRemove from Blivet to DeviceTree.
dwlehman
installerbot-noreply at redhat.com
Tue Mar 17 20:07:38 UTC 2015
From: David Lehman <dlehman at redhat.com>
Also add an option to do the removal directly instead of using actions.
Some of the logic from Blivet.destroyDevice for scheduling of format
destroy actions was copied in as well.
---
blivet/blivet.py | 22 +-------------------
blivet/devicetree.py | 59 ++++++++++++++++++++++++++++++++++++++++++++--------
blivet/populator.py | 6 ++++--
3 files changed, 55 insertions(+), 32 deletions(-)
diff --git a/blivet/blivet.py b/blivet/blivet.py
index c49a380..a9b29a2 100644
--- a/blivet/blivet.py
+++ b/blivet/blivet.py
@@ -607,27 +607,7 @@ def recursiveRemove(self, device):
formatting is removed by no attempt is made to actually remove the
disk device.
"""
- log.debug("removing %s", device.name)
- devices = self.deviceDeps(device)
-
- # this isn't strictly necessary, but it makes the action list easier to
- # read when removing logical partitions because of the automatic
- # renumbering that happens if you remove them in ascending numerical
- # order
- devices.reverse()
-
- while devices:
- log.debug("devices to remove: %s", [d.name for d in devices])
- leaves = [d for d in devices if d.isleaf]
- log.debug("leaves to remove: %s", [d.name for d in leaves])
- for leaf in leaves:
- self.destroyDevice(leaf)
- devices.remove(leaf)
-
- if device.isDisk:
- self.devicetree.registerAction(ActionDestroyFormat(device))
- else:
- self.destroyDevice(device)
+ self.devicetree.recursiveRemove(device)
def clearPartitions(self):
""" Clear partitions and dependent devices from disks.
diff --git a/blivet/devicetree.py b/blivet/devicetree.py
index 8e66c3e..f30c5e8 100644
--- a/blivet/devicetree.py
+++ b/blivet/devicetree.py
@@ -27,6 +27,7 @@
from .actionlist import ActionList
from .errors import DeviceError, DeviceTreeError, StorageError
+from .deviceaction import ActionDestroyDevice, ActionDestroyFormat
from .devices import BTRFSDevice, DASDDevice, NoDevice, PartitionDevice
from . import formats
from .devicelibs import lvm
@@ -223,16 +224,56 @@ def _removeDevice(self, dev, force=None, modparent=True):
dev.name,
dev.id)
- def _removeChildrenFromTree(self, device):
- devs_to_remove = self.getDependentDevices(device)
- while devs_to_remove:
- leaves = [d for d in devs_to_remove if d.isleaf]
+ def recursiveRemove(self, device, actions=True):
+ """ Remove a device after removing its dependent devices.
+
+ :param :class:`~.devices.StorageDevice` device: the device to remove
+ :keyword bool actions: whether to schedule actions for the removal
+
+ If the device is not a leaf, all of its dependents are removed
+ recursively until it is a leaf device. At that point the device is
+ removed, unless it is a disk. If the device is a disk, its
+ formatting is removed by no attempt is made to actually remove the
+ disk device.
+ """
+ log.debug("removing %s", device.name)
+ devices = self.getDependentDevices(device)
+
+ # this isn't strictly necessary, but it makes the action list easier to
+ # read when removing logical partitions because of the automatic
+ # renumbering that happens if you remove them in ascending numerical
+ # order
+ devices.reverse()
+
+ while devices:
+ log.debug("devices to remove: %s", [d.name for d in devices])
+ leaves = [d for d in devices if d.isleaf]
+ log.debug("leaves to remove: %s", [d.name for d in leaves])
for leaf in leaves:
- self._removeDevice(leaf, modparent=False)
- devs_to_remove.remove(leaf)
- if len(devs_to_remove) == 1 and devs_to_remove[0].isExtended:
- self._removeDevice(devs_to_remove[0], force=True, modparent=False)
- break
+ if actions:
+ if leaf.format.exists and not leaf.protected and \
+ not leaf.formatImmutable:
+ self.registerAction(ActionDestroyFormat(leaf))
+
+ self.registerAction(ActionDestroyDevice(leaf))
+ else:
+ if not leaf.formatImmutable:
+ leaf.format = None
+ self._removeDevice(leaf)
+
+ devices.remove(leaf)
+
+ if not device.formatImmutable:
+ if actions:
+ self.registerAction(ActionDestroyFormat(device))
+ else:
+ device.format = None
+
+ if not device.isDisk:
+ if actions:
+ self.registerAction(ActionDestroyDevice(device))
+ else:
+ self._removeDevice(device)
def registerAction(self, action):
""" Register an action to be performed at a later time.
diff --git a/blivet/populator.py b/blivet/populator.py
index acd0f64..d2c20fa 100644
--- a/blivet/populator.py
+++ b/blivet/populator.py
@@ -657,8 +657,10 @@ def addUdevDevice(self, info):
if device.format and device.format.type != "multipath_member":
log.debug("%s newly detected as multipath member, dropping old format and removing kids", device.name)
# remove children from tree so that we don't stumble upon them later
- self.devicetree.removeChildrenFromTree(device)
- device.format = formats.DeviceFormat()
+ for child in self.devicetree.getChildren(device):
+ self.devicetree.recursiveRemove(child, actions=False)
+
+ device.format = None
#
# The first step is to either look up or create the device
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/5a2e84108513b1664ad84ade3028753c305447e6
More information about the anaconda-patches
mailing list