def umount_all(target): """Umount all file systems that are mounted under the target directory""" mpoints = [] for entry in read_fstable('/proc/mounts'): if entry.mpoint.startswith(os.path.abspath(target)): mpoints.append(entry.mpoint) mpoints.sort() for mpoint in reversed(mpoints): try_fail_repeat(umount, mpoint)
def unmap_partition(dev): """Unmap a previously mapped partition""" if not os.path.exists(dev): return try_fail_repeat(dmsetup, 'remove', dev.split('/dev/mapper/')[1])