Re: [PATCH] Make device teardown methods more resilient.

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

 



Looks good.

On 03/11/2009 12:34 PM, David Lehman wrote:
Only perform teardown actions if device status indicates
that the device is active.

Also, do not throw an exception for non-existent devices
if doing a recursive teardown. This gives a chance for
lower-level devices to still get deactivated even if the
higher-level devices have been replaced.
---
  storage/devices.py |   57 ++++++++++++++-------------------------------------
  1 files changed, 16 insertions(+), 41 deletions(-)

diff --git a/storage/devices.py b/storage/devices.py
index 2ae643c..b80eb76 100644
--- a/storage/devices.py
+++ b/storage/devices.py
@@ -513,10 +513,11 @@ class StorageDevice(Device):
      def teardown(self, recursive=None):
          """ Close, or tear down, a device. """
          log_method_call(self, self.name, status=self.status)
-        if not self.exists:
+        if not self.exists and not recursive:
              raise DeviceError("device has not been created")

-        self.format.teardown()
+        if self.status and self.format.exists:
+            self.format.teardown()

          if recursive:
              self.teardownParents(recursive=recursive)
@@ -773,12 +774,6 @@ class DiskDevice(StorageDevice):
          if not os.path.exists(self.path):
              raise DeviceError("device does not exist")

-    def teardown(self, recursive=False):
-        """ Close, or tear down, a device. """
-        log_method_call(self, self.name, status=self.status)
-        if not self.exists:
-            raise DeviceError("device has not been created")
-

  class PartitionDevice(StorageDevice):
      """ A disk partition.
@@ -1227,18 +1222,6 @@ class DMDevice(StorageDevice):
      name = property(lambda d: d._name,
                      lambda d,n: d._setName(n))

-    def teardown(self, recursive=None):
-        """ Close, or tear down, a device. """
-        log_method_call(self, self.name, status=self.status)
-        if not self.exists:
-            raise DeviceError("device has not been created")
-
-        if self.status:
-            self.format.teardown()
-
-        if recursive:
-            self.teardownParents(recursive=recursive)
-

  class DMCryptDevice(DMDevice):
      """ A dm-crypt device """
@@ -1321,11 +1304,13 @@ class LUKSDevice(DMCryptDevice):
      def teardown(self, recursive=False):
          """ Close, or tear down, a device. """
          log_method_call(self, self.name, status=self.status)
-        if not self.exists:
+        if not self.exists and not recursive:
              raise DeviceError("device has not been created")

-        if self.status:
+        if self.status and self.format.exists:
              self.format.teardown()
+
+        if self.slave.format.exists:
              self.slave.format.teardown()

          if recursive:
@@ -1502,7 +1487,7 @@ class LVMVolumeGroupDevice(DMDevice):
      def teardown(self, recursive=None):
          """ Close, or tear down, a device. """
          log_method_call(self, self.name, status=self.status)
-        if not self.exists:
+        if not self.exists and not recursive:
              raise DeviceError("device has not been created")

          if self.status:
@@ -1779,11 +1764,13 @@ class LVMLogicalVolumeDevice(DMDevice):
      def teardown(self, recursive=None):
          """ Close, or tear down, a device. """
          log_method_call(self, self.name, status=self.status)
-        if not self.exists:
+        if not self.exists and not recursive:
              raise DeviceError("device has not been created")

-        if self.status:
+        if self.status and self.format.exists:
              self.format.teardown()
+
+        if self.status:
              lvm.lvdeactivate(self.vg.name, self._name)

          if recursive:
@@ -2088,11 +2075,13 @@ class MDRaidArrayDevice(StorageDevice):
      def teardown(self, recursive=None):
          """ Close, or tear down, a device. """
          log_method_call(self, self.name, status=self.status)
-        if not self.exists:
+        if not self.exists and not recursive:
              raise DeviceError("device has not been created")

-        if self.status:
+        if self.status and self.format.exists:
              self.format.teardown()
+
+        if self.status:
              mdraid.mddeactivate(self.path)

          if recursive:
@@ -2233,10 +2222,6 @@ class DMRaidArrayDevice(DiskDevice):
      def getDMNode(self):
          DMDevice.getDMNode(self)

-    def teardown(self, recursive=None):
-        # avoid DiskDevice's overriding of teardown()
-        StorageDevice.teardown(self, recursive)
-

  class DMRaidPartitionDevice(PartitionDevice):
      """ A disk partition in a dmraid array, identical to a general
@@ -2513,16 +2498,6 @@ class OpticalDevice(StorageDevice):
                                 major=major, minor=minor, exists=True,
                                 parents=parents, sysfsPath=sysfsPath)

-    def teardown(self, recursive=None):
-        """ Close, or tear down, a device. """
-        log_method_call(self, self.name, status=self.status)
-        if not self.exists:
-            raise DeviceError("device has not been created")
-
-        self.format.teardown()
-        if recursive:
-            self.teardownParents(recursive=recursive)
-
      def mediaPresent(self):
          """ Return a boolean indicating whether or not the device contains
              media.


--
David Cantrell <dcantrell@xxxxxxxxxx>
Red Hat / Honolulu, HI

_______________________________________________
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