[PATCH 5/6] Make an extra effort to remove dm partition nodes that want to stay.

David Lehman dlehman at redhat.com
Fri May 2 17:03:42 UTC 2014


When running tests using disk image files it is a fairly regular
occurrence to find that dm device nodes for partitions are not removed
after removing the partition from the disk. lsof and fuser report
nothing, and kpartx -d doesn't think it has anything to do since the
partition table shows no partitions.

The same happens when trying to deactivate them without having removed
them first.
---
 blivet/devices.py | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/blivet/devices.py b/blivet/devices.py
index 79e6c53..8e192fc 100644
--- a/blivet/devices.py
+++ b/blivet/devices.py
@@ -1737,6 +1737,16 @@ class PartitionDevice(StorageDevice):
             self.disk.format.removePartition(part)
             self.disk.format.commit()
 
+    def _postDestroy(self):
+        super(PartitionDevice, self)._postDestroy()
+        if isinstance(self.disk, DMDevice):
+            udev.udev_settle()
+            if self.status:
+                try:
+                    dm.dm_remove(self.name)
+                except (errors.DMError, OSError):
+                    pass
+
     def deactivate(self):
         """
         This is never called. For instructional purposes only.
@@ -1986,6 +1996,10 @@ class DMDevice(StorageDevice):
         if rc:
             raise errors.DMError("partition deactivation failed for '%s'" % self.name)
         udev.udev_settle()
+        for dev in os.listdir("/dev/mapper/"):
+            prefix = self.name + "p"
+            if dev.startswith(prefix) and dev[len(prefix):].isdigit():
+                util.run_program(["dmsetup", "remove", dev])
 
     def _setName(self, name):
         """ Set the device's map name. """
-- 
1.9.0



More information about the anaconda-patches mailing list