Work around kpartx's nonzero exit due to "Device or resource busy" errors

which still permit kpartx to finally remove loop device (LP: #1684090).
Also sync before calling kpartx to let writing to loop devices finish.
core-include-dmsetup
Balint Reczey 8 years ago
parent 0fcff1923c
commit 2569995de8

@ -11,9 +11,22 @@ backing_img=
apt-get -qqy install dosfstools gdisk
clean_loops() {
local kpartx_ret
local kpartx_stdout
if [ -n "${backing_img}" ]; then
kpartx -v -d "${backing_img}"
# sync before removing loop to avoid "Device or resource busy" errors
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
unset backing_img
fi

Loading…
Cancel
Save