diff options
author | Cody A.W. Somerville <cody.somerville@canonical.com> | 2011-07-21 17:00:54 +0200 |
---|---|---|
committer | Daniel Baumann <daniel@debian.org> | 2011-07-21 17:00:54 +0200 |
commit | 0d2cc22efc66e919848fe0b6559e5b59b08e0afa (patch) | |
tree | 7ae736f6f933cbd73759eb010f67010409e34ad4 /functions | |
parent | ebc7a72501339a76f4ab66d37d4aefc0d0ee4a67 (diff) | |
download | vyos-live-build-0d2cc22efc66e919848fe0b6559e5b59b08e0afa.tar.gz vyos-live-build-0d2cc22efc66e919848fe0b6559e5b59b08e0afa.zip |
Adding function for more resilient detachment of loopback devices.
Diffstat (limited to 'functions')
-rwxr-xr-x | functions/losetup.sh | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/functions/losetup.sh b/functions/losetup.sh index df7e2d27f..039ff3ec1 100755 --- a/functions/losetup.sh +++ b/functions/losetup.sh @@ -7,6 +7,29 @@ ## This is free software, and you are welcome to redistribute it ## under certain conditions; see COPYING for details. +Lodetach () +{ + DEVICE="${1}" + ATTEMPT="${2:-1}" + + if [ "${ATTEMPT}" -gt 3 ] + then + Echo_error "Failed to detach loop device '${DEVICE}'." + exit 1 + fi + + # Changes to block devices result in uevents which trigger rules which in + # turn access the loop device (ex. udisks-part-id, blkid) which can cause + # a race condition. We call 'udevadm settle' to help avoid this. + ${LB_ROOT_COMMAND} udevadm settle + + # Loop back devices aren't the most reliable when it comes to writes. + # We sleep and sync for good measure - better than build failure. + sync + sleep 1 + + ${LB_ROOT_COMMAND} ${LB_LOSETUP} -d "${DEVICE}" || Lodetach "${DEVICE}" "$(expr ${ATTEMPT} + 1)" +} Losetup () { @@ -14,9 +37,9 @@ Losetup () FILE="${2}" PARTITION="${3:-1}" - ${LB_ROOT_COMMAND} ${LB_LOSETUP} "${DEVICE}" "${FILE}" + ${LB_ROOT_COMMAND} ${LB_LOSETUP} --read-only "${DEVICE}" "${FILE}" FDISK_OUT="$(${LB_FDISK} -l -u ${DEVICE} 2>&1)" - ${LB_ROOT_COMMAND} ${LB_LOSETUP} -d "${DEVICE}" + Lodetach "${DEVICE}" LOOPDEVICE="$(echo ${DEVICE}p${PARTITION})" |