Skip to content

Instantly share code, notes, and snippets.

@dag-erling
Created August 21, 2023 15:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dag-erling/54d802b614f5a62e4eb959e1198c2e6e to your computer and use it in GitHub Desktop.
Save dag-erling/54d802b614f5a62e4eb959e1198c2e6e to your computer and use it in GitHub Desktop.
#!/bin/sh
: ${n:=$(nproc)}
: ${pool:=zroot}
basefs="${pool}/zfsdl"
set -eu
zfs destroy -r "${basefs}" >/dev/null 2>&1 || true
zfs create -o com.sun:auto-snapshot=false "${basefs}"
basedir="$(zfs get -H -o value mountpoint "${basefs}")"
echo "preparing tarball..." >&2
tarball="${basedir}/zfsdl.tar"
mkdir "${basedir}/src"
(cd /usr/src ; find * -type d) | (cd "${basedir}/src" ; xargs mkdir -p)
(cd /usr/src ; find * -type f) | (cd "${basedir}/src" ; xargs touch)
tar cf "${tarball}" -C "${basedir}" src
zfs_deadlock() {
local fs=$1 dir
zfs create "${fs}"
dir="$(zfs get -H -o value mountpoint "${fs}")"
zfs snapshot "${fs}@empty"
while ! [ -f "${basedir}/stop" ] ; do
echo "fill ${fs}..." >&2
tar xf "${tarball}" -C "${dir}"
echo "rollback ${fs}..." >&2
zfs rollback -rR "${fs}@empty"
done
}
for i in $(seq -w "${n}") ; do
zfs_deadlock "${basefs}/${i}" &
sleep 1
done
wait
echo "stop" >&2
zfs destroy -r "${basefs}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment