diff --git a/etc/nova/rootwrap.d/compute.filters b/etc/nova/rootwrap.d/compute.filters index 607e7376c2ca..db9ee2636a96 100644 --- a/etc/nova/rootwrap.d/compute.filters +++ b/etc/nova/rootwrap.d/compute.filters @@ -185,5 +185,8 @@ lvremove: CommandFilter, /sbin/lvremove, root # nova/virt/libvirt/utils.py: lvcreate: CommandFilter, /sbin/lvcreate, root +# nova/virt/libvirt/utils.py: +lvs: CommandFilter, /sbin/lvs, root + # nova/virt/libvirt/utils.py: vgs: CommandFilter, /sbin/vgs, root diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 693590b385c3..301cfc079a39 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -565,7 +565,9 @@ class LibvirtDriver(driver.ComputeDriver): def fullpath(name): return os.path.join(vg, name) - disk_names = filter(belongs_to_instance, os.listdir(vg)) + logical_volumes = libvirt_utils.list_logical_volumes(vg) + + disk_names = filter(belongs_to_instance, logical_volumes) disks = map(fullpath, disk_names) return disks return [] diff --git a/nova/virt/libvirt/utils.py b/nova/virt/libvirt/utils.py index 1f40bcc7158b..2dc0bfda1625 100644 --- a/nova/virt/libvirt/utils.py +++ b/nova/virt/libvirt/utils.py @@ -138,6 +138,17 @@ def volume_group_free_space(vg): return int(out.strip()) +def list_logical_volumes(vg): + """List logical volumes paths for given volume group. + + :param vg: volume group name + """ + out, err = execute('lvs', '--noheadings', '-o', 'lv_path', vg, + run_as_root=True) + + return [line.strip() for line in out.splitlines()] + + def remove_logical_volumes(*paths): """Remove one or more logical volume.""" if paths: