[PATCH 5/5] Only gather lvm information one time per DeviceTree.populate call.

David Lehman dlehman at redhat.com
Fri Mar 28 20:32:54 UTC 2014


We run one command to gather information about all PVs the first time we
need information about any PV and one command to gather information about
all LVs the first time we need information about any LV. This information
is cached until the next time someone calls DeviceTree.populate or
DeviceTree.dropLVMCache.
---
 blivet/devicetree.py | 36 ++++++++++++++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)

diff --git a/blivet/devicetree.py b/blivet/devicetree.py
index 8d039fd..316501e 100644
--- a/blivet/devicetree.py
+++ b/blivet/devicetree.py
@@ -128,6 +128,9 @@ class DeviceTree(object):
 
         self.unusedRaidMembers = []
 
+        # initialize attributes that may later hold cached lvm info
+        self.dropLVMCache()
+
         self.__passphrases = []
         if passphrase:
             self.__passphrases.append(passphrase)
@@ -161,6 +164,25 @@ class DeviceTree(object):
         self.ignoredDisks.append(disk)
         devicelibs.lvm.lvm_cc_addFilterRejectRegexp(disk)
 
+    @property
+    def pvInfo(self):
+        if self._pvInfo is None:
+            self._pvInfo = devicelibs.lvm.pvinfo()
+
+        return self._pvInfo
+
+    @property
+    def lvInfo(self):
+        if self._lvInfo is None:
+            self._lvInfo = devicelibs.lvm.lvs()
+
+        return self._lvInfo
+
+    def dropLVMCache(self):
+        """ Drop cached lvm information. """
+        self._pvInfo = None
+        self._lvInfo = None
+
     def pruneActions(self):
         """ Remove redundant/obsolete actions from the action list. """
         for action in reversed(self._actions[:]):
@@ -1292,7 +1314,11 @@ class DeviceTree(object):
     def handleVgLvs(self, vg_device):
         """ Handle setup of the LV's in the vg_device. """
         vg_name = vg_device.name
-        lv_info = devicelibs.lvm.lvs(vg_name)
+        if flags.installer_mode:
+            lv_info = devicelibs.lvm.lvs(vg_name)
+        else:
+            lv_info = self.lvInfo
+
         self.names.extend(n for n in lv_info.keys() if n not in self.names)
 
         if not vg_device.complete:
@@ -1749,7 +1775,11 @@ class DeviceTree(object):
             kwargs["biosraid"] = udev_device_is_biosraid_member(info)
         elif format_type == "LVM2_member":
             # lvm
-            pv_info = devicelibs.lvm.pvinfo(device.path)
+            if flags.installer_mode:
+                pv_info = devicelibs.lvm.pvinfo(device.path)
+            else:
+                pv_info = self.pvInfo
+
             info.update(pv_info.get(device.path, {}))
 
             try:
@@ -2035,6 +2065,8 @@ class DeviceTree(object):
         # this has proven useful when populating after opening a LUKS device
         udev_settle()
 
+        self.dropLVMCache()
+
         if flags.installer_mode and not flags.image_install:
             devicelibs.mpath.set_friendly_names(enabled=flags.multipath_friendly_names)
 
-- 
1.9.0



More information about the anaconda-patches mailing list