#!/bin/sh
# DF-2633 Plan-D (stock kernel): tmpfs-backed image (storm conditions),
# fill to wall, phase2, snapshot the media state via dd, leave mounted
# (the caller crashes the VM right after).
set -e
cd /root/df2633
cc -O2 -o write2633 write2633.c
cc -O2 -o phase2 phase2.c

rm -f /tmp/h33.img
truncate -s 256M /tmp/h33.img
vnconfig -c vn1 /tmp/h33.img
newfs_hammer2 -L DATA /dev/vn1 >/dev/null
mkdir -p /mnt/h33
mount_hammer2 /dev/vn1@DATA /mnt/h33
df /mnt/h33

echo "=== fill ==="
./write2633 /mnt/h33 /root/df2633/ctrl 6000
echo "=== phase2 (at the wall) ==="
./phase2 /mnt/h33 /root/df2633/ctrl || true
df /mnt/h33 || true
ls -l /mnt/h33 | head -8 || true
echo "=== sleeping 25s to let the storm brew ==="
sleep 25
echo "=== snapshotting media state (crash semantics) ==="
dd if=/tmp/h33.img of=/root/df2633/storm.img bs=4m 2>&1 | tail -1
md5 /tmp/h33.img || true
md5 /root/df2633/storm.img || true
echo "=== done; caller now crashes the VM ==="
