diff --git a/deploy/mirror-snapshot.sh b/deploy/mirror-snapshot.sh index b65c072..26e9f09 100644 --- a/deploy/mirror-snapshot.sh +++ b/deploy/mirror-snapshot.sh @@ -30,7 +30,10 @@ unmount_view() { umount "$target" 2>/dev/null && return 0 sleep 1 done - return 1 + # A reader can hold the retired view open; a lazy detach removes it from the + # mount table (what ZFS checks) without waiting for that reader to finish. + umount -l "$target" 2>/dev/null || true + ! mountpoint -q "$target" } # A mount shared by several processes disappears for all of them at once, so a # failed attempt is only an error when the entry is still present afterwards. @@ -41,6 +44,12 @@ detach_snapshot_mounts() { [[ -n $target ]] || continue pid=${entry#/proc/}; pid=${pid%/mountinfo} nsenter -t "$pid" -m -- umount "$target" 2>/dev/null || true + if grep -qF " - zfs $snap " "$entry" 2>/dev/null; then + # A container keeps the propagated copy busy (cwd, open files) and + # refuses a normal unmount. A lazy detach drops it from that mount + # table without stopping the container; ZFS only needs the table. + nsenter -t "$pid" -m -- umount -l "$target" 2>/dev/null || true + fi if grep -qF " - zfs $snap " "$entry" 2>/dev/null; then echo "warning: $snap is still mounted at $target in the namespace of pid $pid ($(tr '\0' ' ' < /proc/"$pid"/cmdline 2>/dev/null | cut -c1-60))" >&2 failed=1 diff --git a/tests/control_portal.py b/tests/control_portal.py index a58d47a..fc85bbd 100644 --- a/tests/control_portal.py +++ b/tests/control_portal.py @@ -190,6 +190,9 @@ class Portal(unittest.TestCase): self.assertLess(script.index('detach_snapshot_mounts "$snap"'), destroy) self.assertIn('/proc/[0-9]*/mountinfo', script) self.assertIn('nsenter -t "$pid" -m -- umount', script) + # A container can keep the propagated mount busy; retention must still be + # able to detach it lazily instead of keeping a fourth snapshot. + self.assertIn('nsenter -t "$pid" -m -- umount -l', script) self.assertIn('dataset is busy', script) self.assertIn('umount -l', script)