From dcda67053df5dc0240c743537dc1b9c4a3231b61 Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Thu, 23 Oct 2014 11:28:29 -0400 Subject: [PATCH] Brick LVM: Optimize get_volume When we only want the LV information for a single volume, call "lvs" with the volume name specified. This should reduce unnecessary load of calling "lvs" for the whole VG. Related-Bug: #1373513 Change-Id: Ifbb679e9160f44fe52ecba7bf19aa0eb5bb133f1 --- cinder/brick/local_dev/lvm.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/cinder/brick/local_dev/lvm.py b/cinder/brick/local_dev/lvm.py index 04174c2f0..1befdfa9c 100644 --- a/cinder/brick/local_dev/lvm.py +++ b/cinder/brick/local_dev/lvm.py @@ -233,7 +233,7 @@ class LVM(executor.Executor): return self._supports_lvchange_ignoreskipactivation @staticmethod - def get_all_volumes(root_helper, vg_name=None): + def get_all_volumes(root_helper, vg_name=None, lv_name=None): """Static method to get all LV's on a system. :param root_helper: root_helper to use for execute @@ -245,7 +245,9 @@ class LVM(executor.Executor): cmd = ['env', 'LC_ALL=C', 'lvs', '--noheadings', '--unit=g', '-o', 'vg_name,name,size', '--nosuffix'] - if vg_name is not None: + if lv_name is not None and vg_name is not None: + cmd.append("%s/%s" % (vg_name, lv_name)) + elif vg_name is not None: cmd.append(vg_name) lvs_start = time.time() @@ -265,13 +267,15 @@ class LVM(executor.Executor): return lv_list - def get_volumes(self): + def get_volumes(self, lv_name=None): """Get all LV's associated with this instantiation (VG). :returns: List of Dictionaries with LV info """ - self.lv_list = self.get_all_volumes(self._root_helper, self.vg_name) + self.lv_list = self.get_all_volumes(self._root_helper, + self.vg_name, + lv_name) return self.lv_list def get_volume(self, name): @@ -280,7 +284,7 @@ class LVM(executor.Executor): :returns: dict representation of Logical Volume if exists """ - ref_list = self.get_volumes() + ref_list = self.get_volumes(name) for r in ref_list: if r['name'] == name: return r -- 2.45.2