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 <maksim.malchuk@gmail.com>
This commit is contained in:
parent
174089a6a5
commit
84d6af7de8
@ -15,6 +15,7 @@
|
|||||||
import functools
|
import functools
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import time
|
||||||
|
|
||||||
from diskimage_builder.block_device.exception \
|
from diskimage_builder.block_device.exception \
|
||||||
import BlockDeviceSetupException
|
import BlockDeviceSetupException
|
||||||
@ -109,7 +110,21 @@ class MountPointNode(NodeBase):
|
|||||||
if self.state['filesys'][self.base]['fstype'] != 'vfat':
|
if self.state['filesys'][self.base]['fstype'] != 'vfat':
|
||||||
exec_sudo(["fstrim", "--verbose",
|
exec_sudo(["fstrim", "--verbose",
|
||||||
self.state['mount'][self.mount_point]['path']])
|
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):
|
def delete(self):
|
||||||
self.umount()
|
self.umount()
|
||||||
|
Loading…
Reference in New Issue
Block a user