Fix volume_exists in qubes_lvm
This commit is contained in:
parent
02c8fc999c
commit
ea34c0ed56
@ -66,21 +66,18 @@ 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:
|
||||
|
||||
volume_group.close()
|
||||
return False
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user