mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup.git
synced 2026-10-20 01:43:25 +00:00
fix(backup): mount the zfs snapshot itself so a container can read it
The zfs snapshot was read through <subject>/.zfs/snapshot/<name>. The kernel automounts that directory through a usermode helper that runs in the host's mount namespace, so a containerised baudolo never sees the mount and finds no snapshot. The snapshot is now mounted explicitly at <subject>/.baudolo-<tag>, beside where btrfs carves its own, and removed in order: umount, rmdir, zfs destroy. A failed mount destroys the snapshot at once instead of leaking one per run. The e2e suite could not reach this code at all: zpool create on the /img file failed with "no such pool or dataset", because the kernel opens vdevs from a taskq thread that resolves paths in the host's root, where the container's /img does not exist. The pool now sits on a loop device, whose /dev/loopN node the kernel creates on the host as well, and it is destroyed on exit once this script created it, since a pool is kernel-wide. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -36,9 +36,14 @@ ZFS_READY = "{ [ -c /dev/zfs ] || modprobe zfs 2>/dev/null; }; [ -c /dev/zfs ]"
|
||||
def mount_script(fstype: str) -> str:
|
||||
"""Build a filesystem on a loop device and carve out the snapshot subject."""
|
||||
if fstype == "zfs":
|
||||
# Exception: a loop device, not the /img file, because the kernel opens
|
||||
# vdevs from a taskq thread that resolves paths in the host's root.
|
||||
# The pool is kernel-wide, so it is destroyed on exit, but only once
|
||||
# this script created it.
|
||||
return (
|
||||
f"{PACKAGES} && {ZFS_READY} && truncate -s 400M /img "
|
||||
"&& zpool create -m none baudolo /img "
|
||||
f"{PACKAGES} && {ZFS_READY} && truncate -s 400M /img && {ATTACH} "
|
||||
'&& zpool create -m none baudolo "$LOOP" '
|
||||
"&& trap 'zpool destroy -f baudolo; losetup -d \"$LOOP\"' EXIT "
|
||||
"&& zfs create -o mountpoint=/subject/docker baudolo/docker"
|
||||
)
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user