From d53550cdc6a7ed06ed6ba0ebfdb2ea5004c7c6ff Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Mon, 27 Aug 2018 21:14:48 +0000 Subject: [PATCH] pmb: give loop module time to initialize --- .gitlab-ci.yml | 4 ---- pmb/install/losetup.py | 20 ++++++++++++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2e7fe43f..eefd488c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -102,10 +102,6 @@ pmbootstrap-qemu-tests: # This requires a specific runner, shared runners generally don't work. - qemu script: - # Note: this is a workaround for pmbootstrap's losetup failing - # due to loop devices not coming up fast enough when modprobe is - # called by pmbootstrap. - - "[[ ! -c /dev/loop0 ]] && sudo modprobe loop" # Init test (pipefail disabled so 'yes' doesn't fail test) - "set +o pipefail; yes ''| ./pmbootstrap.py init; set -o pipefail" # Build/install QEMU (so it doesn't timeout in the testcase) diff --git a/pmb/install/losetup.py b/pmb/install/losetup.py index 405a637b..df3dbd27 100644 --- a/pmb/install/losetup.py +++ b/pmb/install/losetup.py @@ -20,6 +20,7 @@ import glob import json import logging import os +import time import pmb.helpers.mount import pmb.helpers.run @@ -40,8 +41,23 @@ def mount(args, img_path): :param img_path: Path to the img file inside native chroot. """ logging.debug("(native) mount " + img_path + " (loop)") - init(args) - pmb.chroot.root(args, ["losetup", "-f", img_path]) + + # Try to mount multiple times (let the kernel module initialize #1594) + for i in range(0, 5): + # Retry + if i > 0: + logging.debug("loop module might not be initialized yet, retry in" + " one second...") + time.sleep(1) + + # Mount and return on success + init(args) + pmb.chroot.root(args, ["losetup", "-f", img_path], check=False) + if device_by_back_file(args, img_path): + return + + # Failure: raise exception + raise RuntimeError("Failed to mount loop device: " + img_path) def device_by_back_file(args, back_file):