From f3c4bfdc33b302010f4cae366dd1de22eab140ba Mon Sep 17 00:00:00 2001 From: BenjiReis Date: Tue, 17 Oct 2023 16:15:29 +0200 Subject: [PATCH] Ensure we can detach when deflate call is not possible Raising during detach call can leak a tapdisk process that will cause trouble later. Signed-off-by: BenjiReis --- drivers/lvhdutil.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/lvhdutil.py b/drivers/lvhdutil.py index 3186b291f..df162de7b 100755 --- a/drivers/lvhdutil.py +++ b/drivers/lvhdutil.py @@ -246,7 +246,7 @@ def attachThin(journaler, srUuid, vdiUuid): lock.release() -def detachThin(session, lvmCache, srUuid, vdiUuid): +def detachThinImpl(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) @@ -273,6 +273,13 @@ def detachThin(session, lvmCache, srUuid, vdiUuid): lock.release() +def detachThin(session, lvmCache, srUuid, vdiUuid): + try: + detachThinImpl(session, lvmCache, srUuid, vdiUuid) + except Exception as e: + util.SMlog(f'Failed to detach properly VDI {vdiUuid}: {e}') + + def createVHDJournalLV(lvmCache, jName, size): """Create a LV to hold a VHD journal""" lvName = "%s_%s" % (JVHD_TAG, jName)