#!/bin/sh
# DF-3067 runner (guest, root): craft an all-PAD 256KB HAMMER undo ring and
# mount it in the background.  Expected: the mount NEVER returns -
# hammer_recover_stage1's version-4 seqno backscan (hammer_recover.c:260-270)
# spins forever through the cyclic PAD-only FIFO.  With
# vfs.hammer.debug_general=0x80 the console floods with "rev scan_offset"
# lines whose offsets CYCLE through the 256KB ring - proof of the unbounded
# walk.  The mount process is stuck in kernel mode; kill -9 cannot remove it.
# Guest otherwise stays up (multi-core).
cd /root
cp /root/base.img /root/hang.img
./padflood backscan /root/hang.img || exit 1
sysctl vfs.hammer.debug_general=0x80
vnconfig -c vn0 /root/hang.img
echo MOUNTING_BG
mount_hammer /dev/vn0 /mnt > /root/mount.out 2>&1 &
MPID=$!
echo "mount pid $MPID"
sleep 20
date
echo "=== ps of mount process ==="
ps auxww | grep -e "$MPID" | grep -v grep
echo "=== kill -9 attempt ==="
kill -9 $MPID 2>/dev/null || true
sleep 3
ps auxww | grep -e "$MPID" | grep -v grep && echo "STILL ALIVE AFTER kill -9" || echo "process gone"
echo "=== walk sample t1 ==="
dmesg | tail -3
sleep 5
echo "=== walk sample t2 (different offsets = walk still cycling) ==="
dmesg | tail -3
echo "=== rev scan_offset lines in ring ==="
dmesg | grep "rev scan_offset" | tail -8
echo ALIVE_AFTER_HANG
