Skip to content

Instantly share code, notes, and snippets.

@adam900710
Created March 5, 2018 10:09
Show Gist options
  • Save adam900710/d37f38070f7fc4d858ffe856c516b426 to your computer and use it in GitHub Desktop.
Save adam900710/d37f38070f7fc4d858ffe856c516b426 to your computer and use it in GitHub Desktop.
Script to reproduce free space cache corruption
#!/bin/bash
dev=/dev/test/scratch1
log_dev=/dev/test/scratch2
table="0 $(blockdev --getsz $log_dev) log-writes $dev $log_dev"
dm_dev=/dev/mapper/log
mnt=/mnt/btrfs
replay_log=/home/adam/log-writes/replay-log
fsstress=/home/adam/xfstests-dev/ltp/fsstress
log_file=replay_check.log
_fail()
{
echo "!!! FAILED: $@ !!!"
exit 1
}
umount $mnt &> /dev/null
umount $dm_dev &> /dev/null
dmsetup remove log &> /dev/null
truncate -s 0 $log_file
dmsetup create log --table "$table"
mkfs.btrfs -f $dm_dev
mount $dm_dev $mnt
btrfs balance --full-balance $mnt
btrfs balance --full-balance $mnt
umount $mnt
dmsetup message log 0 mark mkfs
#mount $dm_dev $mnt -o nospace_cache
mount $dm_dev $mnt
$fsstress -w -n 200 -p 8 -s 1520005265 -d $mnt -v > fsstress.log
dmsetup message log 0 mark fsstress
umount $dm_dev
dmsetup remove log
$replay_log --log $log_dev --replay $dev --end-mark mkfs
#$replay_log --log $log_dev --replay $dev --start-mark mkfs \
# --fsck "btrfs check --check-data-csum $dev" --check flush -v 2>&1 |\
# tee replay_check.log
prev=$($replay_log --log $log_dev --replay $dev --find --end-mark mkfs)
if [ -z $prev ]; then
_fail "failed to locate mark mkfs"
fi
cur=$($replay_log --log $log_dev --replay $dev --find --start-mark mkfs --next-flush)
if [ -z $cur ]; then
_fail "failed to locate initial flush"
fi
cur=$(($cur + 1))
while [ ! -z $cur ]; do
$replay_log --log $log_dev --replay $dev --limit $prev
echo >> $log_file
echo "=== relay log to $cur ===" >> $log_file
$replay_log --log $log_dev --replay $dev --start-entry $prev --limit $(($cur - $prev)) -v >> $log_file
echo "=== fsck on FLUSH: $cur ===" >> $log_file
btrfs check --check-data-csum $dev 2>&1 | tee -a $log_file
if [ $? -ne 0 ]; then
_fail "flush check failed"
fi
echo "=== fsck on FUA: $(($cur + 1)) ===" >> $log_file
$replay_log --log $log_dev --replay $dev --start-entry $cur --limit 1 -v >> $log_file
btrfs check --check-data-csum $dev 2>&1 | tee -a $log_file
if [ $? -ne 0 ]; then
_fail "fua check failed"
fi
prev=$cur
cur=$($replay_log --log $log_dev --replay $dev --start-entry $cur --next-flush --find)
if [ -z $cur ]; then
break;
fi
cur=$(($cur + 1))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment