Fix post-merge audit findings; unify staging teardown
Audit ----- - create_task.py verify failed on a DEFAULT install. hook_status.json emitted a per-file entry for the nested module with ok:false whenever the feature was switched off -- the default -- so verify printed [FAIL] and exited 1, right after the README tells users to run it. Status is now per MODULE with an `active` flag, and verify renders an inactive module as [SKIP]. - A partial apply suppressed the middlewared restart. The exit code conflated "nothing applied" with "one module applied, one failed", so a failing providers patch would prevent the restart that a freshly-applied nested patch needs, leaving it on disk and never loaded. Exit 2 now means partial and the restart still fires. - The native-nested probe could never fire. It scanned crud.py for the guard message, but our own injected block quotes that message, so once applied the probe would always conclude the guard was still present. It now reads only the stock portion of the file. - recover.sh did not unmount staging trees, so an emergency recovery left bind mounts pinning ZFS snapshots that could then never be destroyed. - uninstall.sh deleted sidecar files without reading them. A sidecar is the only record that an interrupted run's snapshot tree is still on disk; both scripts now name the snapshot before clearing it. - Removed a dead branch in the restart gate (unreachable: the kill switch exits). Refactor -------- - Staging teardown had been copy-pasted into uninstall.sh and recover.sh -- two untested shell copies of the fiddly depth-ordering and lazy-umount logic. Both now call `python3 patch/truecloud_nested.py cleanup`, so there is exactly one implementation and it is the one under test. - Dropped the in-memory ACTIVE dict. The sidecar file was already the source of truth; a second in-process record could only desync -- and it is precisely the middlewared-restart case (which empties it) that must not orphan a snapshot tree. One record, on disk, or none. Not done: the overlay-unmount loop is duplicated across apply.sh/uninstall.sh/ recover.sh. It is pre-existing, and apply.sh runs at PREINIT under a tight timeout -- giving it a source dependency would trade 10 lines of duplication for a boot-time failure mode. 74 tests, ruff and shellcheck clean.
This commit is contained in:
+6
-31
@@ -95,38 +95,13 @@ echo ""
|
||||
# These bind mounts pin their ZFS snapshots, so they must go before anything
|
||||
# tries to destroy those snapshots. Deepest first.
|
||||
|
||||
# Delegated to the patch module rather than reimplemented here: the depth
|
||||
# ordering and lazy-umount fallback are fiddly, and a shell copy would be the
|
||||
# untested one.
|
||||
echo "Unmounting nested-snapshot staging trees (if any) ..."
|
||||
_stage_found=0
|
||||
_stage_failed=0
|
||||
# Deepest FIRST, by path depth (slash count) — not string length, which would
|
||||
# let a long shallow path jump ahead of a short deep one and leave a child
|
||||
# mounted (and its ZFS snapshot pinned).
|
||||
while IFS= read -r _mp; do
|
||||
[ -n "$_mp" ] || continue
|
||||
if umount "$_mp" 2>/dev/null || umount -l "$_mp" 2>/dev/null; then
|
||||
echo " Unmounted: $_mp"
|
||||
else
|
||||
echo " WARNING: Could not unmount $_mp"
|
||||
_stage_failed=1
|
||||
fi
|
||||
_stage_found=1
|
||||
done < <(awk '$2 == "/run/truecloud-nested" || index($2, "/run/truecloud-nested/") == 1 {
|
||||
n = gsub(/\//, "/", $2); print n, $2
|
||||
}' /proc/self/mounts 2>/dev/null | sort -rn | cut -d' ' -f2-)
|
||||
|
||||
if [ "$_stage_found" -eq 0 ]; then
|
||||
echo " None active."
|
||||
fi
|
||||
|
||||
# NEVER `rm -rf` here: if an unmount failed, that would recurse *through* a live
|
||||
# bind mount into the ZFS snapshot behind it. Remove empty directories only.
|
||||
if [ "$_stage_failed" -eq 0 ]; then
|
||||
find /run/truecloud-nested -depth -type d -exec rmdir {} + 2>/dev/null || true
|
||||
rm -f /run/truecloud-nested/*.snapshot 2>/dev/null || true
|
||||
rmdir /run/truecloud-nested 2>/dev/null || true
|
||||
else
|
||||
echo " WARNING: staging mounts remain; leaving /run/truecloud-nested in place."
|
||||
echo " Unmount them manually, then remove the directory."
|
||||
if ! python3 "$PATCH_DIR/patch/truecloud_nested.py" cleanup; then
|
||||
echo " WARNING: staging mounts remain. Unmount them manually; until you do,"
|
||||
echo " the ZFS snapshots they pin cannot be destroyed."
|
||||
fi
|
||||
|
||||
# The opt-in marker lives in the repo dir; remove it so a later re-install
|
||||
|
||||
Reference in New Issue
Block a user