From 84d6af7de8d5d311da0761d9aa685256b7315439 Mon Sep 17 00:00:00 2001 From: Maksim Malchuk Date: Wed, 1 Feb 2023 20:05:51 +0300 Subject: [PATCH] Repeat to umount filesystem when exception occurs Sometimes umount doesn't have much time to finish and failed with error 'target is busy', but this is not an actual error in some cases and the operation should be repeated again with some timeout. This solves the issue and raise actual exception only after several tries with timeout. Closes-Bug: #2004492 Change-Id: I069af85b52e20e9fd688f9ae07e66beb2179f3e1 Signed-off-by: Maksim Malchuk --- diskimage_builder/block_device/level3/mount.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/diskimage_builder/block_device/level3/mount.py b/diskimage_builder/block_device/level3/mount.py index 963f12b5..085f03f3 100644 --- a/diskimage_builder/block_device/level3/mount.py +++ b/diskimage_builder/block_device/level3/mount.py @@ -15,6 +15,7 @@ import functools import logging import os +import time from diskimage_builder.block_device.exception \ import BlockDeviceSetupException @@ -109,7 +110,21 @@ class MountPointNode(NodeBase): if self.state['filesys'][self.base]['fstype'] != 'vfat': exec_sudo(["fstrim", "--verbose", self.state['mount'][self.mount_point]['path']]) - exec_sudo(["umount", self.state['mount'][self.mount_point]['path']]) + # Even 'fstrim' call sometimes don't solve the issue with 'busy' + # filesystem, so we need to catch the exception and repeat unount. + mount_point = self.state['mount'][self.mount_point]['path'] + catch = None + for try_cnt in range(10, 1, -1): + try: + exec_sudo(["umount", mount_point]) + return + except BlockDeviceSetupException as e: + catch = e + logger.error("umount failed (%s)", e.output.strip()) + time.sleep(3) + + logger.debug("Gave up trying to umount [%s]", mount_point) + raise catch def delete(self): self.umount()