From c1100fa461c35310e7b76097cccc3f2b40f8c76b Mon Sep 17 00:00:00 2001 From: Ricardo Pardini Date: Wed, 18 Jan 2023 17:24:19 +0100 Subject: [PATCH] armbian-next: still fighting `tee` leaking under duress, turns out I _hadn't_ really won - last resort, use lazy umount. - include `lsof` in hostdeps, useful to debug these situations --- lib/functions/host/prepare-host.sh | 2 +- lib/functions/host/tmpfs-utils.sh | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/functions/host/prepare-host.sh b/lib/functions/host/prepare-host.sh index 11494f67f..2de4dcb99 100644 --- a/lib/functions/host/prepare-host.sh +++ b/lib/functions/host/prepare-host.sh @@ -245,7 +245,7 @@ function adaptative_prepare_host_dependencies() { kmod # this causes initramfs rebuild, but is usually pre-installed, so no harm done unless it's an upgrade libbison-dev libelf-dev libfdt-dev libfile-fcntllock-perl libmpc-dev libfl-dev liblz4-tool libncurses-dev libssl-dev libusb-1.0-0-dev - linux-base locales + linux-base locales lsof ncurses-base ncurses-term # for `make menuconfig` ntpdate patchutils pkg-config pv diff --git a/lib/functions/host/tmpfs-utils.sh b/lib/functions/host/tmpfs-utils.sh index f09b8e69d..e317260fb 100644 --- a/lib/functions/host/tmpfs-utils.sh +++ b/lib/functions/host/tmpfs-utils.sh @@ -71,11 +71,24 @@ function cleanup_tmpfs_for() { if [[ "${umount_tmpfs}" == "umount_tmpfs" ]]; then display_alert "cleanup_tmpfs_for: umount tmpfs" "${tmpfs_name}" "cleanup" cd "${SRC}" || echo "cleanup_tmpfs_for: cd failed to ${SRC}" >&2 # avoid cwd in use error - umount "${tmpfs_path}" || { - display_alert "cleanup_tmpfs_for: umount failed" "${tmpfs_name} tmpfs umount failed" "err" + sync # let disk coalesce + umount "${tmpfs_path}" &> /dev/null || { + display_alert "cleanup_tmpfs_for: umount failed" "${tmpfs_name} tmpfs umount failed, will try lazy" "cleanup" + # Do a lazy umount... last-resort... + sync + umount -l "${tmpfs_path}" &> /dev/null || display_alert "cleanup_tmpfs_for: lazy umount failed" "${tmpfs_name} tmpfs lazy umount also failed" "cleanup" + sync + } + + # Check if the tmpfs is still mounted after all that trying, log error, show debug, and give up with error + mountpoint -q "${tmpfs_path}" && { + display_alert "cleanup_tmpfs_for: umount failed" "${tmpfs_name} tmpfs still mounted after retries/lazy umount" "err" # Show last-resort what's in there / what's using it to stderr ls -la "${tmpfs_path}" >&2 || echo "cleanup_tmpfs_for: ls failed" >&2 lsof "${tmpfs_path}" >&2 || echo "cleanup_tmpfs_for: lsof dir failed" >&2 + return 1 # sorry, we tried. + } || { + display_alert "cleanup_tmpfs_for: umount success" "${tmpfs_name}" "cleanup" } else display_alert "cleanup_tmpfs_for: not umounting tmpfs" "${tmpfs_name}" "cleanup"