#!/bin/sh
#
# run_panic_test.sh - DF-2643 reproduction on the HARNESS kernel (K2 =
# stock code + harness.diff sysctl knob).  Simulates the exact state the
# hammer2_admin.c:556-563 race admits: the inode cluster chain NULLing
# between xop_start and the xop thread run.
#
# EXPECTED (stock write path, no NULL guard): after `sync` triggers the
# strategy write, the kernel takes a NULL-deref page fault INSIDE
# hammer2_chain_lookup -- "Stopped at hammer2_chain_lookup+0x92:
# movzbl 0x98(%rbx),%eax" -- and halts at db> (all CPUs stopped).
set -e
truncate -s 512M /root/w.img
newfs_hammer2 /root/w.img >/dev/null 2>&1
vn=$(vnconfig -c vn /root/w.img)
mount_hammer2 /dev/$vn@LOCAL /mnt
echo "MOUNT_OK (unit $vn)"
sysctl vfs.hammer2.df2643_harness=1
echo "KNOB_ON -- writing (buffered) then sync to fire strategy write"
dd if=/dev/zero of=/mnt/tfile bs=64k count=1
sync
echo "UNREACHABLE ON STOCK WRITE PATH: machine should be at db> now"
