armbian-next: refactor losetup -d ... into free_loop_device_insistent() which retries 10 times

This commit is contained in:
Ricardo Pardini
2023-01-03 16:06:31 +01:00
parent f679b81b10
commit 3bc8afd593
3 changed files with 15 additions and 15 deletions

View File

@@ -51,18 +51,8 @@ function check_loop_device_internal() {
return 0
}
#
# Copyright (c) 2013-2021 Igor Pecovnik, igor.pecovnik@gma**.com
#
# This file is licensed under the terms of the GNU General Public
# License version 2. This program is licensed "as is" without any
# warranty of any kind, whether express or implied.
#
# This file is a part of the Armbian build script
# https://github.com/armbian/build/
# write_uboot <loopdev>
#
# write_uboot_to_loop_image <loopdev>
# @TODO: isnt this supposed to be u-boot related? why in loop.sh?
write_uboot_to_loop_image() {
local loop=$1 revision
@@ -102,3 +92,14 @@ write_uboot_to_loop_image() {
return 0
}
# This exists to prevent silly failures; sometimes the user is inspecting the directory outside of build, etc.
function free_loop_device_insistent() {
display_alert "Freeing loop device" "${1}"
do_with_retries 10 free_loop_device_retried "${1}"
}
function free_loop_device_retried() {
display_alert "Freeing loop device (try ${RETRY_RUNS})" "${1}"
losetup -d "${1}"
}

View File

@@ -88,8 +88,7 @@ create_image_from_sdcard_rootfs() {
Called after unmounting both `/root` and `/boot`.
POST_UMOUNT_FINAL_IMAGE
display_alert "Freeing loop device" "${LOOP}"
losetup -d "${LOOP}"
free_loop_device_insistent "${LOOP}"
unset LOOP # unset so cleanup handler does not try it again
# We're done with ${MOUNT} by now, remove it.

View File

@@ -129,7 +129,7 @@ function trap_handler_cleanup_rootfs_and_image() {
# shellcheck disable=SC2153 # global var.
if [[ -b "${LOOP}" ]]; then
display_alert "Freeing loop" "trap_handler_cleanup_rootfs_and_image ${LOOP}" "wrn"
losetup -d "${LOOP}" >&2 || true
free_loop_device_insistent "${LOOP}" || true
fi
[[ -d "${SDCARD}" ]] && rm -rf --one-file-system "${SDCARD}"