Change in vdsm[master]: lvm: Invalidate lvm cache after extend

nsoffer at redhat.com nsoffer at redhat.com
Tue Nov 12 18:57:01 UTC 2013


Nir Soffer has uploaded a new change for review.

Change subject: lvm: Invalidate lvm cache after extend
......................................................................

lvm: Invalidate lvm cache after extend

After extending a vg, lvm filter is updated with the new pv, but cached
pv are never updated. This cause commands that use short filter to fail,
and then they are run again without the short filter.

This patch adds a grace period where cache is invalidated if we find
that the short filter is stale and long filter is good. The first
failing command using short filter invoked after vg was extended will
invalidate the cache.

Change-Id: I96e628174143fc887e649fe67f2f1171fc176cca
Relates-To: https://bugzilla.redhat.com/1022976
Signed-off-by: Nir Soffer <nsoffer at redhat.com>
---
M vdsm/storage/hsm.py
M vdsm/storage/lvm.py
2 files changed, 20 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/92/21192/1

diff --git a/vdsm/storage/hsm.py b/vdsm/storage/hsm.py
index a508051..c9afb4f 100644
--- a/vdsm/storage/hsm.py
+++ b/vdsm/storage/hsm.py
@@ -2005,7 +2005,7 @@
         :rtype: dict
         """
         visibility = self.scanDevicesVisibility(guids)
-        lvm.invalidateFilter()
+        lvm.prepareForExtend()
         for guid in guids:
             if visibility[guid]:
                 visibility[guid] = (os.stat('/dev/mapper/' + guid).st_mode &
diff --git a/vdsm/storage/lvm.py b/vdsm/storage/lvm.py
index f730adc..e9e8b35 100644
--- a/vdsm/storage/lvm.py
+++ b/vdsm/storage/lvm.py
@@ -30,6 +30,7 @@
 import re
 import pwd
 import grp
+import time
 import logging
 from collections import namedtuple
 import pprint as pp
@@ -291,6 +292,13 @@
         self.invalidateFilter()
         self.flush()
 
+    def prepareForExtend(self):
+        self._lastExtended = time.time()
+        self.invalidateFilter()
+
+    def wasExtendedRecently(self):
+        return time.time() - self._lastExtended < 300.0
+
     def __init__(self):
         self._filterStale = True
         self._extraCfg = None
@@ -303,20 +311,28 @@
         self._pvs = {}
         self._vgs = {}
         self._lvs = {}
+        self._lastExtended = 0.0
 
     def cmd(self, cmd, devices=tuple()):
+        # First try using short filter if devices were specified
         finalCmd = self._addExtraCfg(cmd, devices)
         rc, out, err = misc.execCmd(finalCmd, sudo=True)
         if rc != 0:
             # Filter might be stale
             self.invalidateFilter()
+            # Try again with long filter
             newCmd = self._addExtraCfg(cmd)
             # Before blindly trying again make sure
             # that the commands are not identical, because
             # the devlist is sorted there is no fear
             # of two identical filters looking differently
             if newCmd != finalCmd:
-                return misc.execCmd(newCmd, sudo=True)
+                rc, out, err = misc.execCmd(newCmd, sudo=True)
+                if rc == 0 and devices and self.wasExtendedRecently():
+                    # Looks like the cache is stale. It would be nice to
+                    # invalidate only the pvs, but I'm not sure it works, so
+                    # lets invalidate the whole thing.
+                    self.flush()
 
         return rc, out, err
 
@@ -1313,8 +1329,8 @@
     return [lv for lv in getLV(vgName) if tag in lv.tags]
 
 
-def invalidateFilter():
-    _lvminfo.invalidateFilter()
+def prepareForExtend():
+    _lvminfo.prepareForExtend()
 
 
 # Fix me: unify with addTag


-- 
To view, visit http://gerrit.ovirt.org/21192
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I96e628174143fc887e649fe67f2f1171fc176cca
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer at redhat.com>


More information about the vdsm-patches mailing list