Skip to content

Instantly share code, notes, and snippets.

@loli10K
Created April 26, 2017 18:07
Show Gist options
  • Save loli10K/cc5b56612aa74871397066c2f6ac75d8 to your computer and use it in GitHub Desktop.
Save loli10K/cc5b56612aa74871397066c2f6ac75d8 to your computer and use it in GitHub Desktop.
reproducer-CKSUM-errors-raidz1
# misc functions
function is_linux() {
if [[ "$(uname)" == "Linux" ]]; then
return 0
else
return 1
fi
}
function zpool_status() {
zpool status -v $POOLNAME | grep 'scan:'
}
function zdb_dtl() {
pool="$1"
zdb -ddd $pool | sed -e '1,/Dirty/d' -e "/Dataset $pool/,\$d"
}
function zpool_offline() {
pool="$1"
device="$2"
ret=1
while [[ $ret -ne 0 ]]; do zpool offline $pool $device; ret=$?; sleep 1; done
while [[ `zpool status $pool | egrep -c "$device.*OFFLINE"` -ne 1 ]]; do sleep 1; done
}
function zpool_online() {
pool="$1"
device="$2"
ret=1
while [[ $ret -ne 0 ]]; do zpool online $pool $device; ret=$?; sleep 1; done
while [[ `zpool status $pool | egrep -c "$device.*ONLINE"` -ne 1 ]]; do sleep 1; done
}
function zpool_scrub() {
pool="$1"
ret=1
while [[ $ret -ne 0 ]]; do zpool scrub $pool; ret=$?; sleep 1; done
while [[ `zpool status $pool | egrep -c "scan: scrub in progress"` -eq 1 ]]; do sleep 1; done
}
# env
POOLNAME='testpool'
TMPDIR='/var/tmp'
DISKNUM=3
# os specific stuff
if is_linux; then
TMPDIR='/var/tmp'
mountpoint -q $TMPDIR || mount -t tmpfs tmpfs $TMPDIR
for i in `seq 1 $DISKNUM`
do
rm -f $TMPDIR/zpool_$i.dat
fallocate -l 64m $TMPDIR/zpool_$i.dat
done
else
TMPDIR='/tmp'
for i in `seq 1 $DISKNUM`
do
rm -f $TMPDIR/zpool_$i.dat
mkfile 64m $TMPDIR/zpool_$i.dat
done
fi
# create the pool
zpool destroy -f $POOLNAME
zpool create -O mountpoint=$TMPDIR/$POOLNAME $POOLNAME raidz1 $TMPDIR/zpool_*.dat
zpool_status
# offline the first device
zpool_offline $POOLNAME $TMPDIR/zpool_1.dat
# write to the pool
dd if=/dev/urandom of=$TMPDIR/$POOLNAME/data.dat bs=1M count=128
# dump the DTL entries before the scrub
zdb_dtl $POOLNAME
# scrub the pool
zpool_scrub $POOLNAME
# dump the DTL entries after the scrub
zdb_dtl $POOLNAME
# online the first device
zpool_online $POOLNAME $TMPDIR/zpool_1.dat
zpool_status
# offline the second device
zpool_offline $POOLNAME $TMPDIR/zpool_2.dat
# scrub the pool
zpool_scrub $POOLNAME
# check the pool
zpool status -v $POOLNAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment