From a8a8396fa33be875694c7e2ff5df48bf58aa0cb8 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Sat, 1 Aug 2026 08:46:32 +0200 Subject: [PATCH] fix(ci): claim the loop device atomically and survive a docker-less node The data-root task runs on all five swarm nodes at once, and they are containers on one host kernel sharing its loop devices. losetup -f only names the next free one; by the time the following losetup attached it, a sibling had taken it - 'failed to set up loop device: Device or resource busy'. Claim with --find --show, which picks and attaches in one call, and retry with a short pause when a sibling wins anyway. The step runs before anything is pulled, so on some nodes docker is not installed yet and the closing 'systemctl start docker' died with rc=5, taking the whole task with it under set -e. The two systemctl stop calls above it had tolerated that all along. Start only when the unit exists, and report applied-pending-docker instead of applied so the job summary stops claiming a data root that no daemon has picked up yet. Co-Authored-By: Claude Opus 5 (1M context) --- .../utils/filesystem/docker_dataroot.sh | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/scripts/tests/deploy/utils/filesystem/docker_dataroot.sh b/scripts/tests/deploy/utils/filesystem/docker_dataroot.sh index ed6e83db31..b47e7a2bac 100755 --- a/scripts/tests/deploy/utils/filesystem/docker_dataroot.sh +++ b/scripts/tests/deploy/utils/filesystem/docker_dataroot.sh @@ -128,9 +128,20 @@ systemctl stop docker 2>/dev/null || true mkdir -p "${MOUNT}" "$(dirname "${IMAGE}")" rm -f "${IMAGE}" truncate -s "${SIZE}" "${IMAGE}" -LOOP="$(losetup -f | awk '{print $1}')" -[ -b "${LOOP}" ] || mknod "${LOOP}" b 7 "${LOOP#/dev/loop}" -losetup "${LOOP}" "${IMAGE}" +LOOP="" +attempt=0 +while [ -z "${LOOP}" ] && [ "${attempt}" -lt 16 ]; do + attempt=$((attempt + 1)) + [ "${attempt}" -eq 1 ] || sleep 0.5 + candidate="" + if candidate="$(losetup -f 2>/dev/null)" && [ -n "${candidate}" ] && [ ! -b "${candidate}" ]; then + mknod "${candidate}" b 7 "${candidate#/dev/loop}" 2>/dev/null || candidate="" + fi + if attached="$(losetup --find --show "${IMAGE}" 2>/dev/null)"; then + LOOP="${attached}" + fi +done +[ -n "${LOOP}" ] || decline "no loop device could be claimed after ${attempt} attempts" if [ "${FSTYPE}" = zfs ]; then zpool create -f -m "${MOUNT}" "${POOL}" "${LOOP}" @@ -157,5 +168,10 @@ config["data-root"] = root path.write_text(json.dumps(config, indent=2) + "\n") PYTHON -systemctl start docker -verdict applied +if systemctl cat docker.service >/dev/null 2>&1; then + systemctl start docker + verdict applied +else + report "docker.service is not installed yet; the data root takes effect when it is" + verdict applied-pending-docker +fi