From 250aeb5d219db1a0fc01033168a55f7f61e60c74 Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Fri, 16 Jun 2017 09:26:06 -0700 Subject: [PATCH] Fix mkfs failure when loop device is not ready There was a race in diskimage-builder where the mkfs call after a kpartx -avs for the loop device would fail because the device was not yet ready. This adds a udevadm settle call after the kpartx to make sure the udev event queue has cleared. Change-Id: I90103b59357edebbac7a641e8980cb282d37561b Closes-Bug: #1698337 --- diskimage_builder/block_device/level1/partitioning.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/diskimage_builder/block_device/level1/partitioning.py b/diskimage_builder/block_device/level1/partitioning.py index f7fd07ced..926207e68 100644 --- a/diskimage_builder/block_device/level1/partitioning.py +++ b/diskimage_builder/block_device/level1/partitioning.py @@ -147,6 +147,12 @@ class Partitioning(PluginBase): # mount them if not os.path.exists("/.dockerenv"): exec_sudo(["kpartx", "-avs", device_path]) + # We need to make sure udev finishes creating the device + # before continuting, so "udevadm settle". Otherwise later + # commands can fail with "file does not exist". + # XXX: "-s" (synchronous) to kpartx should avoid this, + # but experience shows it does not. + exec_sudo(["udevadm", "settle"]) else: # If running inside Docker, make our nodes manually, # because udev will not be working. kpartx cannot run in