#!/bin/sh
# DF-4800 PoC setup: 2 md drives w/ GPT vinum partitions + mirrored vinum
# volume (2 concat plexes, one sd each), 3 MB data, distinctive pattern.
# Mirrors the DF-4482 topology.
#
# NB: vinum reserves the first 265 sectors of each drive for the label
# and config; the sd DATA window on each drive is sectors [265, 265+6144)
# (see the DF-4714 pack: "4361s = 265s vinum label/config reserve + 4096s
# first sd").  All compares/clobbers use that window only.
DATA_SKIP=265
DATA_CNT=6144
kldload vinum >/dev/null 2>&1
for u in 0 1; do
  dd if=/dev/zero of=/dev/md${u} bs=1m count=12 >/dev/null 2>&1
  gpt create -f md${u} >/dev/null 2>&1
  gpt add -t vinum -s 8192 md${u} >/dev/null 2>&1
done
printf "drive d1 device /dev/md0s0\ndrive d2 device /dev/md1s0\nvolume vol\n plex org concat\n  sd length 3m drive d1\n plex org concat\n  sd length 3m drive d2\n" > /tmp/vc.txt
vinum create -f /tmp/vc.txt >/dev/null 2>&1
for o in vol.p0.s0 vol.p1.s0 vol.p0 vol.p1 vol; do
  vinum setstate -f up $o >/dev/null 2>&1
done
sleep 1
# distinctive, non-repeating pattern written through the VOLUME (both plexes)
dd if=/dev/urandom of=/tmp/pat bs=1m count=3 2>/dev/null
dd if=/tmp/pat of=/dev/vinum/vol/vol bs=1m conv=notrunc 2>/dev/null
# snapshot the reference copies of the DATA window on each drive
dd if=/dev/md0s0 of=/tmp/ref0 bs=512 skip=$DATA_SKIP count=$DATA_CNT 2>/dev/null
dd if=/dev/md1s0 of=/tmp/ref1 bs=512 skip=$DATA_SKIP count=$DATA_CNT 2>/dev/null
cmp -s /tmp/ref0 /tmp/ref1 && echo "SETUP: plex data windows identical before revive" || echo "SETUP: WARNING data windows differ already"
# stale plex1 + clobber its data window entirely (worst-case stale content)
vinum setstate stale vol.p1.s0 >/dev/null 2>&1
dd if=/dev/zero of=/dev/md1s0 bs=512 seek=$DATA_SKIP count=$DATA_CNT 2>/dev/null
echo "== state before concurrent revive =="
vinum list | tr -d "\r" | grep -E "^V |^P |^S "
