#!/bin/sh
# DF-2630 fix validation on kernel #1 (both fixes applied).
set -x
D=/root/poc/fix2630
mkdir -p $D
sysctl vfs.usermount
mkdir -p /mnt/h2 /mnt/h2b /mnt/h2d
echo '=== A. sanity: stock single-device image mounts/ls/umount fine ==='
vnconfig -c vn0 /root/poc/base.img
mount -t hammer2 -o ro /dev/vn0@testvol /mnt/h2
echo "SANITY_MOUNT_RC=$?"
ls /mnt/h2
echo "SANITY_LS_RC=$?"
umount /mnt/h2
echo "SANITY_UMOUNT_RC=$?"
vnconfig -u vn0

echo '=== B. control image (pfs_nmasters=1): no wedge ==='
vnconfig -c vn0 /root/poc/control.img
mount -t hammer2 -o ro /dev/vn0@testvol /mnt/h2
echo "CONTROL_MOUNT_RC=$?"
ls /mnt/h2
echo "CONTROL_LS_RC=$?"
umount /mnt/h2
echo "CONTROL_UMOUNT_RC=$?"
vnconfig -u vn0

echo '=== C. wedge image (pfs_nmasters=2) with root_timeout=5 ==='
sysctl vfs.hammer2.root_timeout=5
vnconfig -c vn0 /root/poc/wedge.img
date +%s > $D/ts1
mount -t hammer2 -o ro /dev/vn0@testvol /mnt/h2
echo "WEDGE_MOUNT_RC=$?"
date +%s
echo '--- ls #1: should block ~5s then FAIL (no permanent wedge) ---'
date +%s
ls /mnt/h2
echo "WEDGE_LS1_RC=$?"
date +%s
echo '--- ls #2: sticky-fail immediate ---'
date +%s
ls /mnt/h2
echo "WEDGE_LS2_RC=$?"
date +%s
echo '--- census: any h2root/vfs_busy waiters? ---'
ps axlw | grep -E "h2root|vfs_busy|ncplk" | grep -v grep
echo "CENSUS_DONE"
echo '--- dmesg: quorum failure message ---'
dmesg | grep -E "root quorum|VFS_ROOT" | tail -3
echo '--- other hammer2 mounts still possible (system healthy)? ---'
vnconfig -c vn1 /root/poc/base2.img
mount -t hammer2 -o ro /dev/vn1@othervol /mnt/h2b
echo "HEALTH_MOUNT_RC=$?"
ls /mnt/h2b
echo "HEALTH_LS_RC=$?"
echo '--- can the wedged mount be removed? ---'
timeout 15 umount -f /mnt/h2
echo "WEDGE_UMOUNTF_RC=$?"
echo '--- final state ---'
ps axlw | grep -E "h2root|vfs_busy|ncplk" | grep -v grep
echo VALIDATION_C_DONE
