#!/bin/sh
# DF-4895 racer: administratively flap each drive down->up while the
# writers hammer the volume.  'vinum setstate -f down <drive>' runs
# set_drive_state(drive_down, force), which queues daemonrq_closedrive;
# the vinum daemon then runs close_locked_drive(): vn_close(drive->vp)
# and drive->vp = NULL -- with no synchronization against requests that
# are still between their first and second phase (built while the drive
# was up).  The next complete_raid5_write() for such a request calls
# vn_strategy(drive->vp=NULL) => fatal trap 12 (or strategy on a
# concurrently-closed vnode).
round=0
while [ ! -f /tmp/stop_race ]; do
  round=$((round+1))
  if [ $((round % 2)) -eq 0 ]; then D=d1; else D=d2; fi
  vinum setstate -f down $D >/dev/null 2>&1
  vinum setstate -f up $D >/dev/null 2>&1
  # bring the subdisks/plex/volume back up so writers resume normal
  # (read-modify-write) builds and generate fresh racing cohorts
  for o in rv.p0.s0 rv.p0.s1 rv.p0.s2 rv.p0 rv; do
    vinum setstate -f up $o >/dev/null 2>&1
  done
  echo "round $round ($D)" >> /tmp/race_rounds
done
echo RACEDONE >> /tmp/race_rounds
