3 # Copyright (c) 2013 Fusion IO, Inc. All Rights Reserved.
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation.
9 # This program is distributed in the hope that it would be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write the Free Software Foundation,
16 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 # common functions for setting up and tearing down a dmflakey device
26 local BLK_DEV_SIZE=`blockdev --getsz $SCRATCH_DEV`
27 FLAKEY_DEV=/dev/mapper/flakey-test
28 FLAKEY_TABLE="0 $BLK_DEV_SIZE flakey $SCRATCH_DEV 0 180 0"
29 FLAKEY_TABLE_DROP="0 $BLK_DEV_SIZE flakey $SCRATCH_DEV 0 0 180 1 drop_writes"
30 $DMSETUP_PROG create flakey-test --table "$FLAKEY_TABLE" || \
31 _fatal "failed to create flakey device"
32 $DMSETUP_PROG mknodes > /dev/null 2>&1
37 mount -t $FSTYP $MOUNT_OPTIONS $FLAKEY_DEV $SCRATCH_MNT
42 $UMOUNT_PROG $SCRATCH_MNT
47 # If dmsetup load fails then we need to make sure to do resume here
48 # otherwise the umount will hang
49 $DMSETUP_PROG resume flakey-test > /dev/null 2>&1
50 $UMOUNT_PROG $SCRATCH_MNT > /dev/null 2>&1
51 $DMSETUP_PROG remove flakey-test > /dev/null 2>&1
52 $DMSETUP_PROG mknodes > /dev/null 2>&1
55 # _load_flakey_table <table> [lockfs]
57 # This defaults to --nolockfs, which doesn't freeze_fs() before loading the new
58 # table, so it simulates power failure.
63 [ $1 -eq $FLAKEY_DROP_WRITES ] && table="$FLAKEY_TABLE_DROP"
65 suspend_opt="--nolockfs"
66 [ $# -gt 1 ] && [ $2 -eq 1 ] && suspend_opt=""
68 $DMSETUP_PROG suspend $suspend_opt flakey-test
69 [ $? -ne 0 ] && _fatal "failed to suspend flakey-test"
71 $DMSETUP_PROG load flakey-test --table "$table"
72 [ $? -ne 0 ] && _fatal "failed to load table into flakey-test"
74 $DMSETUP_PROG resume flakey-test
75 [ $? -ne 0 ] && _fatal "failed to resumeflakey-test"