From 2498aadebb3bf4cfcf07772a2563fb5b58917022 Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Fri, 20 Mar 2020 14:08:22 +1300 Subject: [PATCH] Call udevadm settle before kpartx -d Back in 2017 some code was added to ignore failures tearing down loop devices. But debugging that growpart race on cloud images made me (very) aware of a potential cause of the race: doing something like zerofree on a device will cause udev scripts to run, and if they are still running by the time kpartx is called, you would expect the kpartx -d to fail. So lets see if a udevadm settle helps, and get rid of one of the "sometimes this fails but we don't know why" comments... --- debian/changelog | 6 ++++++ live-build/functions | 16 +++++----------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/debian/changelog b/debian/changelog index 12684083..44ca88bc 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +livecd-rootfs (2.656) UNRELEASED; urgency=medium + + * Call udevadm settle before kpartx -d. + + -- Michael Hudson-Doyle Sat, 21 Mar 2020 00:07:43 +1300 + livecd-rootfs (2.655) focal; urgency=medium * minimized: reinstall packages one by one, instead of all of them diff --git a/live-build/functions b/live-build/functions index 4daa6932..9e2def5a 100644 --- a/live-build/functions +++ b/live-build/functions @@ -14,18 +14,12 @@ clean_loops() { local kpartx_stdout if [ -n "${backing_img}" ]; then - # sync before removing loop to avoid "Device or resource busy" errors + # If something just finished writing to the device or a + # partition (e.g. the zerofree in umount_partition) udev might + # still be processing the device. + udevadm settle sync - kpartx_ret="" - kpartx_stdout=$(kpartx -v -d "${backing_img}") || kpartx_ret=$? - echo "$kpartx_stdout" - if [ -n "$kpartx_ret" ]; then - if echo "$kpartx_stdout" | grep -q "loop deleted"; then - echo "Suppressing kpartx returning error (#860894)" - else - exit $kpartx_ret - fi - fi + kpartx -v -d "${backing_img}" unset backing_img fi