From 9d3f524c6926edfbff5f62308c8d582edcc7067f Mon Sep 17 00:00:00 2001 From: zhoudongshu Date: Thu, 10 Jan 2013 20:23:49 +0800 Subject: Correct the calculating of disk size when using lvm disk backend. Currently, disk space size calculating in nova doesn't consider the situation when lvm is used as disk backend. Thus both used and total disk size are not correct when we use lvm to create instance. This patch fixes this problem by using 'vgs' to get disk size in such case. Fixes LP #1098116. Change-Id: I0e86649cfde83a154d0a4c034ca52abe73384e73 --- nova/virt/libvirt/driver.py | 18 ++++++++++++++---- nova/virt/libvirt/utils.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index ea6e0e6a0..89f49b225 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -2032,8 +2032,13 @@ class LibvirtDriver(driver.ComputeDriver): """ - stats = libvirt_utils.get_fs_info(CONF.instances_path) - return stats['total'] / (1024 ** 3) + if CONF.libvirt_images_type == 'lvm': + vg_total = libvirt_utils.volume_group_total_space( + CONF.libvirt_images_volume_group) + return vg_total / (1024 ** 3) + else: + stats = libvirt_utils.get_fs_info(CONF.instances_path) + return stats['total'] / (1024 ** 3) def get_vcpu_used(self): """Get vcpu usage number of physical computer. @@ -2101,8 +2106,13 @@ class LibvirtDriver(driver.ComputeDriver): """ - stats = libvirt_utils.get_fs_info(CONF.instances_path) - return stats['used'] / (1024 ** 3) + if CONF.libvirt_images_type == 'lvm': + vg_used = libvirt_utils.volume_group_used_space( + CONF.libvirt_images_volume_group) + return vg_used / (1024 ** 3) + else: + stats = libvirt_utils.get_fs_info(CONF.instances_path) + return stats['used'] / (1024 ** 3) def get_hypervisor_type(self): """Get hypervisor type. diff --git a/nova/virt/libvirt/utils.py b/nova/virt/libvirt/utils.py index 73c3b552b..9c8d192c7 100644 --- a/nova/virt/libvirt/utils.py +++ b/nova/virt/libvirt/utils.py @@ -144,6 +144,36 @@ def volume_group_free_space(vg): return int(out.strip()) +def volume_group_total_space(vg): + """Return total space on volume group in bytes. + + :param vg: volume group name + """ + + out, err = execute('vgs', '--noheadings', '--nosuffix', + '--units', 'b', '-o', 'vg_size', vg, + run_as_root=True) + return int(out.strip()) + + +def volume_group_used_space(vg): + """Return available space on volume group in bytes. + + :param vg: volume group name + """ + + out, err = execute('vgs', '--noheadings', '--nosuffix', + '--separator', '|', + '--units', 'b', '-o', 'vg_size,vg_free', vg, + run_as_root=True) + + info = out.split('|') + if len(info) != 2: + raise RuntimeError(_("vg %s must be LVM volume group") % vg) + + return int(info[0]) - int(info[1]) + + def list_logical_volumes(vg): """List logical volumes paths for given volume group. -- cgit