Skip to content

Commit

Permalink
CA-385069: Remove unnecessary LvmContext wrap
Browse files Browse the repository at this point in the history
This was resulting in a deadlock condition being detected and is no
longer required after the chnages for CP-39600 in 125aa9e.

Signed-off-by: Mark Syms <[email protected]>
  • Loading branch information
MarkSymsCtx committed Feb 5, 2024
1 parent 2d763cb commit 7434118
Showing 1 changed file with 41 additions and 43 deletions.
84 changes: 41 additions & 43 deletions drivers/LVHDSR.py
Original file line number Diff line number Diff line change
Expand Up @@ -1762,51 +1762,49 @@ def _snapshot(self, snapType, cloneOp=False, cbtlog=None, cbt_consistency=None):
util.fistpoint.activate("LVHDRT_clone_vdi_after_create_journal", self.sr.uuid)

try:
with lvutil.LvmLockContext():
# self becomes the "base vdi"
origOldLV = self.lvname
baseLV = lvhdutil.LV_PREFIX[self.vdi_type] + baseUuid
self.sr.lvmCache.rename(self.lvname, baseLV)
self.sr.lvActivator.replace(self.uuid, baseUuid, baseLV, False)
RefCounter.set(baseUuid, 1, 0, lvhdutil.NS_PREFIX_LVM + self.sr.uuid)
self.uuid = baseUuid
self.lvname = baseLV
self.path = os.path.join(self.sr.path, baseLV)
self.label = "base copy"
self.read_only = True
self.location = self.uuid
self.managed = False

# shrink the base copy to the minimum - we do it before creating
# the snapshot volumes to avoid requiring double the space
if self.vdi_type == vhdutil.VDI_TYPE_VHD:
lvhdutil.deflate(self.sr.lvmCache, self.lvname, lvSizeBase)
self.utilisation = lvSizeBase
util.fistpoint.activate("LVHDRT_clone_vdi_after_shrink_parent", self.sr.uuid)

snapVDI = self._createSnap(origUuid, lvSizeOrig, False)
util.fistpoint.activate("LVHDRT_clone_vdi_after_first_snap", self.sr.uuid)
snapVDI2 = None
if snapType == VDI.SNAPSHOT_DOUBLE:
snapVDI2 = self._createSnap(clonUuid, lvSizeClon, True)
# If we have CBT enabled on the VDI,
# set CBT status for the new snapshot disk
if cbtlog:
snapVDI2.cbt_enabled = True
util.fistpoint.activate("LVHDRT_clone_vdi_after_second_snap", self.sr.uuid)

# note: it is important to mark the parent hidden only AFTER the
# new VHD children have been created, which are referencing it;
# otherwise we would introduce a race with GC that could reclaim
# the parent before we snapshot it
if self.vdi_type == vhdutil.VDI_TYPE_RAW:
self.sr.lvmCache.setHidden(self.lvname)
else:
vhdutil.setHidden(self.path)
util.fistpoint.activate("LVHDRT_clone_vdi_after_parent_hidden", self.sr.uuid)
# self becomes the "base vdi"
origOldLV = self.lvname
baseLV = lvhdutil.LV_PREFIX[self.vdi_type] + baseUuid
self.sr.lvmCache.rename(self.lvname, baseLV)
self.sr.lvActivator.replace(self.uuid, baseUuid, baseLV, False)
RefCounter.set(baseUuid, 1, 0, lvhdutil.NS_PREFIX_LVM + self.sr.uuid)
self.uuid = baseUuid
self.lvname = baseLV
self.path = os.path.join(self.sr.path, baseLV)
self.label = "base copy"
self.read_only = True
self.location = self.uuid
self.managed = False

# shrink the base copy to the minimum - we do it before creating
# the snapshot volumes to avoid requiring double the space
if self.vdi_type == vhdutil.VDI_TYPE_VHD:
lvhdutil.deflate(self.sr.lvmCache, self.lvname, lvSizeBase)
self.utilisation = lvSizeBase
util.fistpoint.activate("LVHDRT_clone_vdi_after_shrink_parent", self.sr.uuid)

snapVDI = self._createSnap(origUuid, lvSizeOrig, False)
util.fistpoint.activate("LVHDRT_clone_vdi_after_first_snap", self.sr.uuid)
snapVDI2 = None
if snapType == VDI.SNAPSHOT_DOUBLE:
snapVDI2 = self._createSnap(clonUuid, lvSizeClon, True)
# If we have CBT enabled on the VDI,
# set CBT status for the new snapshot disk
if cbtlog:
snapVDI2.cbt_enabled = True
util.fistpoint.activate("LVHDRT_clone_vdi_after_second_snap", self.sr.uuid)

# note: it is important to mark the parent hidden only AFTER the
# new VHD children have been created, which are referencing it;
# otherwise we would introduce a race with GC that could reclaim
# the parent before we snapshot it
if self.vdi_type == vhdutil.VDI_TYPE_RAW:
self.sr.lvmCache.setHidden(self.lvname)
else:
vhdutil.setHidden(self.path)
util.fistpoint.activate("LVHDRT_clone_vdi_after_parent_hidden", self.sr.uuid)

# set the base copy to ReadOnly
# Do this outside the LvmLockContext to avoid deadlock
self.sr.lvmCache.setReadonly(self.lvname, True)
util.fistpoint.activate("LVHDRT_clone_vdi_after_parent_ro", self.sr.uuid)

Expand Down

0 comments on commit 7434118

Please sign in to comment.