From ea34c0ed569c9cb82127081f1c83f3aba6bc67a5 Mon Sep 17 00:00:00 2001 From: Bahtiar `kalkin-` Gadimov Date: Wed, 3 Aug 2016 02:07:32 +0200 Subject: [PATCH] Fix volume_exists in qubes_lvm --- qubes/tools/qubes_lvm.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/qubes/tools/qubes_lvm.py b/qubes/tools/qubes_lvm.py index 8e367b88..e3a083ea 100644 --- a/qubes/tools/qubes_lvm.py +++ b/qubes/tools/qubes_lvm.py @@ -66,22 +66,19 @@ def pool_exists(args): return False -def thin_volume_exists(volume): +def volume_exists(volume): """ Check if the given volume exists and is a thin volume """ log.debug("Checking if the %s thin volume exists", volume) assert volume is not None - - cmd = ['sudo', 'lvs', '-o', 'lv_modules', '--rows', volume] - try: - output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) - log.debug(output) - # Just because the above command succeded it does not mean that we - # really have a volume managed by a thin pool. It could be just any - # volume. Below we check that the volume uses the thin-pool module. - if "thin-pool,thin" in output: + vg_name, volume_name = volume.split('/', 1) + volume_group = lvm.vgOpen(vg_name) + for p in volume_group.listLVs(): + if p.getAttr()[0] == 'V' and p.getName() == volume_name: + volume_group.close() return True - except subprocess.CalledProcessError: - return False + + volume_group.close() + return False def remove_volume(args): @@ -92,7 +89,7 @@ def remove_volume(args): process still has the volume locked. """ img = args.name - if not thin_volume_exists(img): + if not volume_exists(img): log.info("Expected to remove %s, but volume does not exist", img) return