[blivet:rhel7/master 2/8] Make DeviceTree.hide() remove a larger set (#1043763)

mulhern amulhern at redhat.com
Mon Mar 3 21:33:40 UTC 2014


Related: rhbz#1043763

If a device is hidden these things now happen:
1) All actions are canceled. Note that canceling a device create action will
cause the device to be removed. Note that it should be the case that no
existing device has a device create action associated with it.
Previously only a subset of actions were canceled.
2) The device being hidden is removed using _removeDevice. An additional
post-processing step adds the name of the device back into self.names.
Other steps associated with hiding the device remain the same.

Note: The device exists if and only if it has not been removed by the
cancellation of all actions. So, if it does not exist, then the method
is done after action cancelation. However, if the device does exist, it should
be removed, special hiding actions should be done, and its name should be
inserted back into self.names.

Signed-off-by: mulhern <amulhern at redhat.com>
---
 blivet/devicetree.py | 51 ++++++++++++++++++++++++++++++++-------------------
 1 file changed, 32 insertions(+), 19 deletions(-)

diff --git a/blivet/devicetree.py b/blivet/devicetree.py
index 8a79f14..1b283ec 100644
--- a/blivet/devicetree.py
+++ b/blivet/devicetree.py
@@ -1792,6 +1792,32 @@ class DeviceTree(object):
                 devicelibs.lvm.lvm_cc_addFilterRejectRegexp(pv.name)
 
     def hide(self, device):
+        """Removes this device and devices that depend on it.
+
+           Removes all actions.
+
+           If a device exists, performs some special actions and places
+           it on a list of hidden devices.
+
+           Mixes recursion and side effects, most significantly in the code
+           that removes all the actions. However, this code is a null op
+           in every case except the first base case that is reached,
+           where all actions are removed. This means that when a device
+           is removed explicitly in this function by means of a direct call to
+           _removeDevices it is guaranteed that all actions have already
+           been canceled.
+
+           The recursion guarantees that when a device is removed by an explicit
+           _removeDevice call it is a leaf device.
+
+           It also guarantees that hidden devices are added to self._hidden
+           in a topologically sorted order (assuming edges are child
+           relationships), leaves first.
+
+           If a device does not exist then it must have been removed by the
+           cancelation of all the actions, so it does not need to be removed
+           explicitly.
+        """
         if device in self._hidden:
             return
 
@@ -1803,35 +1829,22 @@ class DeviceTree(object):
                                                   device.id))
 
         for action in reversed(self._actions):
-            if not action.device.dependsOn(device) and action.device != device:
-                continue
-
-            log.debug("cancelling action: %s" % action)
-            try:
-                action.cancel()
-            except Exception:
-                log.warning("failed to cancel action while hiding %s: %s"
-                            % (device.name, action))
-            finally:
-                self._actions.remove(action)
-
-        # XXX modifications that do not require actions, like setting a
-        #     mountpoint, will not be reversed here
-
-        # we're intentionally not modifying self.names here
-        self._devices.remove(device)
-        for parent in device.parents:
-            parent.removeChild()
+            self.cancelAction(action)
 
         if not device.exists:
             return
 
+        self._removeDevice(device, moddisk=False)
+
         self._hidden.append(device)
         lvm.lvm_cc_addFilterRejectRegexp(device.name)
 
         if isinstance(device, DASDDevice):
             self.dasd.removeDASD(device)
 
+        if device.name not in self.names:
+            self.names.append(device.name)
+
     def unhide(self, device):
         # the hidden list should be in leaves-first order
         for hidden in reversed(self._hidden):
-- 
1.8.3.1



More information about the anaconda-patches mailing list