Re: [PATCH] Save a copy of the device stack so we can destroy the format. (#489975)

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

 





David Lehman wrote:
Since everything is a reference, we are subject to any changes that
may be made to the device/format stack occupied by "our" format from
the time the action is created to the time it is executed. If devices
lower in the stack have their formats scheduled for destruction, we
will be unable to setup the device on which "our" format exists
(because the ActionDestroyFormat constructor unsets the device's
format attribute so the tree can reflect the future state of things).
So, we save a deep copy and are no longer subject to changes
initiated from outside our sphere of interest.
---
 storage/deviceaction.py |   19 ++++++++++++++-----
 1 files changed, 14 insertions(+), 5 deletions(-)


A bit tricky, but other then that it looks good.

Regards,

Hans

diff --git a/storage/deviceaction.py b/storage/deviceaction.py
index 7d6e836..f9a7322 100644
--- a/storage/deviceaction.py
+++ b/storage/deviceaction.py
@@ -21,6 +21,7 @@
 # Red Hat Author(s): Dave Lehman <dlehman@xxxxxxxxxx>
 #
+import copy
 from parted import PARTITION_BOOT
from udev import udev_settle
@@ -143,7 +144,7 @@ class DeviceAction(object):
         if not isinstance(device, StorageDevice):
             raise ValueError("arg 1 must be a StorageDevice instance")
         self.device = device
-        #self._backup = deepcopy(device)
+
def execute(self, intf=None):
         """ perform the action """
@@ -296,7 +297,12 @@ class ActionDestroyFormat(DeviceAction):
def __init__(self, device):
         DeviceAction.__init__(self, device)
-        self.origFormat = device.format
+        # Save a deep copy of the device stack this format occupies.
+        # This is necessary since the stack of devices and formats
+        # required to get to this format may get yanked out from under
+        # us between now and execute.
+        self._device = copy.deepcopy(device)
+        self.origFormat = self._device.format
         if device.format.exists:
             device.format.teardown()
         self.device.format = None
@@ -309,13 +315,16 @@ class ActionDestroyFormat(DeviceAction):
                 # unset partition flags and commit
                 self.device.unsetFlag(self.origFormat.partedFlag)
                 self.device.disk.commit()
-
                 udev_settle()
- self.device.setup()
+            # set up our copy of the original device stack since the
+            # reference we got may have had any number of things changed
+            # since then (most notably, formats removed by this very
+            # class' constructor)
+            self._device.setup()
             self.origFormat.destroy()
             udev_settle()
-            self.device.teardown()
+            self._device.teardown()
def cancel(self):
         self.device.format = self.origFormat

_______________________________________________
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