Commit 71916f3a authored by segfault's avatar segfault

Check for errors before and after mounting overlayfs

parent 7670688f
......@@ -21,6 +21,8 @@ START_TIMEOUT = 5
STOP_TIMEOUT = 5
APT_UPDATE_TIMEOUT = 60
APT_INSTALL_TIMEOUT = 60
OVERLAY_MOUNT_TIMEOUT = 5
OVERLAY_UNMOUNT_TIMEOUT = 5
class ContainerError(Exception):
......@@ -164,14 +166,32 @@ class ContainerManager(object):
# https://github.com/systemd/systemd/issues/3847
logger.debug("Mounting overlay of %r", self.name)
if self.overlay_is_mounted():
logger.warning("Directory %r is already mounted. Trying to unmount")
# Ensure that the overlay is not already mounted. It might also be mounted multiple times,
# so we use a loop here.
start_time = time.perf_counter()
while time.perf_counter() - start_time < OVERLAY_UNMOUNT_TIMEOUT:
if not self.overlay_is_mounted():
break
logger.warning("Overlay of %r is already mounted. Trying to unmount", self.name)
self.unmount_overlay()
if self.overlay_is_mounted():
raise ContainerError("Failed to mount overlay of %r: Overlay is already mounted and cannot be unmounted "
"(timeout: %s)" % (self.name, OVERLAY_UNMOUNT_TIMEOUT))
sh.mount("-t", "overlay", "overlay",
"-olowerdir=%s,upperdir=%s,workdir=%s" % (self.lowerdir, self.upperdir, self.workdir),
str(self.machine_dir))
# Ensure that the overlay is mounted
start_time = time.perf_counter()
while time.perf_counter() - start_time < OVERLAY_MOUNT_TIMEOUT:
if self.overlay_is_mounted():
return
time.sleep(0.1)
raise ContainerError("Failed to mount overlay of %r (timeout: %s)", self.name, OVERLAY_MOUNT_TIMEOUT)
def unmount_overlay(self):
sh.umount("-f", str(self.machine_dir))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment