From 79943dbb0063a379aae5f85efbab377338cdc6c8 Mon Sep 17 00:00:00 2001 From: BenjiReis Date: Tue, 17 Oct 2023 16:01:48 +0200 Subject: [PATCH] Remove SR lock during thin attach/detach This lock is normally useless and can create a dead lock when thin mode is activated: - A task try to deactivate a volume during a VM shutdown on a slave (so a VDI A is locked). Then a new task is created on the master host, we try to get the SR lock on the master. - In parallel a tap-pause is asked from the master to the slave, the master SR lock is now locked. The tap-pause request is received on the slave, but we can't lock VDI A because it's already locked. So to resume: a dead lock is only possible if we try to shutdown a VM with a particular VDI and if we try to snapshot it in the same time. Signed-off-by: BenjiReis --- drivers/lvhdutil.py | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/drivers/lvhdutil.py b/drivers/lvhdutil.py index 3186b291..37bc762c 100755 --- a/drivers/lvhdutil.py +++ b/drivers/lvhdutil.py @@ -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) @@ -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( \ @@ -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):