Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CA-385069: Remove unnecessary LvmContext wrap #671

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading