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

lvutil: Remove SR lock during thin attach/detach #648

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
18 changes: 0 additions & 18 deletions drivers/lvhdutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,25 +213,11 @@ def setSizeVirt(journaler, srUuid, vdiUuid, size, jFile):
vhdutil.setSizeVirt(path, size, jFile)


def _tryAcquire(lock):
"""We must give up if the SR is locked because it could be locked by the
coalesce thread trying to acquire the VDI lock we're holding, so as to
avoid deadlock"""
for i in range(LOCK_RETRY_ATTEMPTS):
gotLock = lock.acquireNoblock()
if gotLock:
return
time.sleep(1)
raise util.SRBusyException()


def attachThin(journaler, srUuid, vdiUuid):
"""Ensure that the VDI LV is expanded to the fully-allocated size"""
lvName = LV_PREFIX[vhdutil.VDI_TYPE_VHD] + vdiUuid
vgName = VG_PREFIX + srUuid
lock = Lock(vhdutil.LOCK_TYPE_SR, srUuid)
lvmCache = journaler.lvmCache
_tryAcquire(lock)
lvmCache.refresh()
vhdInfo = vhdutil.getVHDInfoLVM(lvName, extractUuid, vgName)
newSize = calcSizeVHDLV(vhdInfo.sizeVirt)
Expand All @@ -243,15 +229,12 @@ def attachThin(journaler, srUuid, vdiUuid):
inflate(journaler, srUuid, vdiUuid, newSize)
finally:
lvmCache.deactivate(NS_PREFIX_LVM + srUuid, vdiUuid, lvName, False)
lock.release()


def detachThin(session, lvmCache, srUuid, vdiUuid):
"""Shrink the VDI to the minimal size if no one is using it"""
lvName = LV_PREFIX[vhdutil.VDI_TYPE_VHD] + vdiUuid
path = os.path.join(VG_LOCATION, VG_PREFIX + srUuid, lvName)
lock = Lock(vhdutil.LOCK_TYPE_SR, srUuid)
_tryAcquire(lock)

vdiRef = session.xenapi.VDI.get_by_uuid(vdiUuid)
vbds = session.xenapi.VBD.get_all_records_where( \
Expand All @@ -270,7 +253,6 @@ def detachThin(session, lvmCache, srUuid, vdiUuid):
deflate(lvmCache, lvName, newSize)
finally:
lvmCache.deactivate(NS_PREFIX_LVM + srUuid, vdiUuid, lvName, False)
lock.release()


def createVHDJournalLV(lvmCache, jName, size):
Expand Down