#!/bin/sh
# DF-2585 stress — churn + sync on a live 2-chain hammer2 cluster (CLUS).
# The VOLHDR flush of iroot (vfs_sync stage 2) runs the volume-dedup check
# at flush.c:1377-1384 on clindex-1 xop threads; churn creates/repoints
# inodes and dirties iroot metadata concurrently.
i=0
end=$(( ${1:-180} ))
t0=$(date +%s)
while [ $(( $(date +%s) - t0 )) -lt $end ]; do
  i=$((i+1))
  echo "stress $i" > /mnt/c2/f.$i
  mv /mnt/c2/f.$i /mnt/c2/g.$i
  chmod 664 /mnt/c2/g.$i 2>/dev/null
  rm -f /mnt/c2/g.$i
  mkdir /mnt/c2/d.$i && rmdir /mnt/c2/d.$i
  # iroot metadata churn (mtime/ctime on the PFS root):
  chmod 1777 /mnt/c2 2>/dev/null
  chmod 755 /mnt/c2 2>/dev/null
done
echo "CHURN-DONE iterations=$i"
