Skip to content

Commit 2473186

Browse files
klmp200Wescoeur
authored andcommitted
fix(LVMSR): deactivate unused LVM snap base before deletion (#130)
During normal operations, unused LV bases appear to stay enabled on slaves after they get deleted, causing an accumulation of activated deleted LVs on slaves. This is mostly benign and this automatically gets resolved after a reboot of the slave. But if it accumulates a lot (on a big infra for example) it causes LVM commands to slow down so much that the whole SR gets unusable. Signed-off-by: Antoine Bartuccio <antoine.bartuccio@vates.tech>
1 parent ed8fc55 commit 2473186

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

drivers/LVHDSR.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,13 +1248,6 @@ def call_on_slave(self, args, host_refs, message: str):
12481248
if not rv:
12491249
raise Exception('plugin %s failed' % self.PLUGIN_ON_SLAVE)
12501250

1251-
def _updateSlavesPreClone(self, hostRefs, origOldLV):
1252-
args = {"vgName": self.vgname,
1253-
"action1": "deactivateNoRefcount",
1254-
"lvName1": origOldLV}
1255-
message = "Deactivate VDI"
1256-
self.call_on_slave(args, hostRefs, message)
1257-
12581251
def _updateSlavesOnClone(self, hostRefs, origOldLV, origLV,
12591252
baseUuid, baseLV):
12601253
"""We need to reactivate the original LV on each slave (note that the
@@ -1292,6 +1285,16 @@ def _updateSlavesOnRemove(self, hostRefs, baseUuid, baseLV):
12921285
message = f"Cleaning locks for {baseLV}"
12931286
self.call_on_slave(args, hostRefs, message)
12941287

1288+
def _deactivateOnSlave(self, hostRefs, lvname):
1289+
"""Tell the slave we need to deactivate the base image"""
1290+
args = {
1291+
"vgName": self.vgname,
1292+
"action1": "deactivateNoRefcount",
1293+
"lvName1": lvname}
1294+
1295+
message = f"Deactivating {lvname}"
1296+
self.call_on_slave(args, hostRefs, message)
1297+
12951298
def _cleanup(self, skipLockCleanup=False):
12961299
"""delete stale refcounter, flag, and lock files"""
12971300
RefCounter.resetAll(lvhdutil.NS_PREFIX_LVM + self.uuid)
@@ -1760,7 +1763,7 @@ def _snapshot(self, snapType, cloneOp=False, cbtlog=None, cbt_consistency=None):
17601763
self.sr._ensureSpaceAvailable(size_req)
17611764

17621765
if hostRefs:
1763-
self.sr._updateSlavesPreClone(hostRefs, self.lvname)
1766+
self.sr._deactivateOnSlave(hostRefs, self.lvname)
17641767

17651768
baseUuid = util.gen_uuid()
17661769
origUuid = self.uuid
@@ -1890,6 +1893,13 @@ def _finishSnapshot(self, snapVDI, snapVDI2, hostRefs, cloneOp=False, snapType=N
18901893
util.SMlog("%s != %s != %s => deleting unused base %s" % \
18911894
(snapParent, self.uuid, snap2Parent, self.lvname))
18921895
RefCounter.put(self.uuid, False, lvhdutil.NS_PREFIX_LVM + self.sr.uuid)
1896+
1897+
# The removed LV could still be activated on a slave host if it's
1898+
# part of a VM currently running there, we need to deactivate it
1899+
# before it gets removed to avoid a LV leak.
1900+
if hostRefs:
1901+
self.sr._deactivateOnSlave(hostRefs, self.lvname)
1902+
18931903
self.sr.lvmCache.remove(self.lvname)
18941904
self.sr.lvActivator.remove(self.uuid, False)
18951905
if hostRefs:

0 commit comments

Comments
 (0)