summaryrefslogtreecommitdiffstats
path: root/storage/devices.py
diff options
context:
space:
mode:
authorDavid Lehman <dlehman@redhat.com>2009-03-11 17:06:55 -0500
committerDavid Lehman <dlehman@redhat.com>2009-03-11 18:22:54 -0500
commit4d33bbb4729e10a19905a63a0dc0df222cf6469c (patch)
tree77494b24257f0e999053442fce6404d7d509d323 /storage/devices.py
parent37a23a7c937240437e9db965e688f8bf0b0877be (diff)
downloadanaconda-4d33bbb4729e10a19905a63a0dc0df222cf6469c.tar.gz
anaconda-4d33bbb4729e10a19905a63a0dc0df222cf6469c.tar.xz
anaconda-4d33bbb4729e10a19905a63a0dc0df222cf6469c.zip
Make device teardown methods more resilient.
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.
Diffstat (limited to 'storage/devices.py')
-rw-r--r--storage/devices.py57
1 files changed, 16 insertions, 41 deletions
diff --git a/storage/devices.py b/storage/devices.py
index 2ae643cc6..b80eb7600 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.