Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions os/rauc/loop-wait.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# shellcheck shell=bash
#
# Shared by mkimage.sh (builds a slot image) and tests/os/verify-image.sh (checks one): the wait
# for a loop device's partition nodes to exist. `losetup -P` returns before the kernel/udev
# publish them, and the gap widens under loop-device churn (a KVM battery running beside a release
# build) — without the wait, the first mkfs/mount fails with "No such device or address" and a
# plain retry succeeds, which is exactly how it stays invisible until release day. This started as
# two copies of the same nine lines and drifted in wording; the callers keep their own error
# message (mkimage.sh's build failure reads differently from verify-image.sh's "broken image"
# verdict), only the polling loop is shared.

# $1 = loop device (e.g. /dev/loop0). Waits for its p1+p2 nodes — the appliance image is
# exactly ESP + slot A, so both callers want exactly this pair. Returns 0 once both are block
# devices, 1 if they never showed up.
wait_loop_partitions() {
udevadm settle 2>/dev/null || true
for _ in {1..25}; do
[ -b "${1}p1" ] && [ -b "${1}p2" ] && return 0
sleep 0.2
done
[ -b "${1}p1" ] && [ -b "${1}p2" ]
}
15 changes: 4 additions & 11 deletions os/rauc/mkimage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ SIZE_GIB="${PITHEAD_IMAGE_GIB:-5}"
TARBALL="os/build/pithead-root.tar"
# shellcheck source=os/rauc/populate-slot.sh
. os/rauc/populate-slot.sh
# shellcheck source=os/rauc/loop-wait.sh
. os/rauc/loop-wait.sh

[ -s "$TARBALL" ] || {
echo "missing $TARBALL — run os/build-image.sh first to stage the rootfs" >&2
Expand Down Expand Up @@ -67,17 +69,8 @@ cleanup() {
}
trap cleanup EXIT

# losetup -P returns before the kernel/udev publish the partition nodes, and the gap widens
# under loop-device churn (a KVM battery running beside a release build). Without this wait the
# first mkfs fails with "unable to open ${LOOP}p1: No such device or address" — and a plain
# retry succeeds, which is exactly how it stays invisible until release day. One guarded wait:
# settle udev, then poll briefly for both nodes.
udevadm settle 2>/dev/null || true
for _ in {1..25}; do
[ -b "${LOOP}p1" ] && [ -b "${LOOP}p2" ] && break
sleep 0.2
done
[ -b "${LOOP}p1" ] && [ -b "${LOOP}p2" ] || {
# See loop-wait.sh for why this wait exists.
wait_loop_partitions "$LOOP" || {
echo "partition nodes for $LOOP never appeared after losetup -P" >&2
exit 1
}
Expand Down
4 changes: 0 additions & 4 deletions tests/os/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ while [ $# -gt 0 ]; do
PHASE="$2"
shift 2
;;
--vm)
VM="$2"
shift 2
;;
-h | --help)
sed -n '2,20p' "$0" | sed 's/^# \{0,1\}//'
exit 0
Expand Down
19 changes: 10 additions & 9 deletions tests/os/verify-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
# Exit: 0 all checks pass, 1 otherwise.
set -uo pipefail

# Directory-independent: this script assumes cwd == repo root for the relative paths later on
# (./pithead, build/dashboard/...), so resolve the shared helper from the script's own location
# instead of adding a cd that would change those.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
# shellcheck source=os/rauc/loop-wait.sh
. "$SCRIPT_DIR/../../os/rauc/loop-wait.sh"

IMAGE="${1:-}"
MODE="${2:-}"
[ -f "$IMAGE" ] || {
Expand Down Expand Up @@ -47,15 +54,9 @@ cleanup() {
}
trap cleanup EXIT

# Same race as mkimage.sh: losetup -P returns before the partition nodes exist. Wait once here
# so the checks below read the image, not the timing of udev on a busy box.
udevadm settle 2>/dev/null || true
for _ in {1..25}; do
[ -b "${LOOP}p1" ] && [ -b "${LOOP}p2" ] && break
sleep 0.2
done
# Hard-fail like mkimage.sh does: a mount error two screens later names the wrong culprit.
[ -b "${LOOP}p1" ] && [ -b "${LOOP}p2" ] || {
# Same race as mkimage.sh (see loop-wait.sh). Hard-fail like it does: a mount error two screens
# later names the wrong culprit.
wait_loop_partitions "$LOOP" || {
echo "partition nodes never appeared on $LOOP — udev timing or a broken image" >&2
exit 1
}
Expand Down
Loading