From 3b32ef23768521f3bedfff5bfc956b18240702b9 Mon Sep 17 00:00:00 2001 From: David Lehman Date: Fri, 21 Feb 2014 16:32:43 -0600 Subject: [PATCH 05/13] Make an extra effort to remove dm partition nodes that want to stay. 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 a712522..4dc4ee4 100644 --- a/blivet/devices.py +++ b/blivet/devices.py @@ -1732,6 +1732,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 (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