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
24 echo $MOUNT_OPTIONS | grep -q dax
26 _notrun "Cannot run tests with DAX on dmflakey devices"
31 local BLK_DEV_SIZE=`blockdev --getsz $SCRATCH_DEV`
32 FLAKEY_DEV=/dev/mapper/flakey-test
33 FLAKEY_TABLE="0 $BLK_DEV_SIZE flakey $SCRATCH_DEV 0 180 0"
34 FLAKEY_TABLE_DROP="0 $BLK_DEV_SIZE flakey $SCRATCH_DEV 0 0 180 1 drop_writes"
35 $DMSETUP_PROG create flakey-test --table "$FLAKEY_TABLE" || \
36 _fatal "failed to create flakey device"
37 $DMSETUP_PROG mknodes > /dev/null 2>&1
42 mount -t $FSTYP $MOUNT_OPTIONS $FLAKEY_DEV $SCRATCH_MNT
47 $UMOUNT_PROG $SCRATCH_MNT
52 # If dmsetup load fails then we need to make sure to do resume here
53 # otherwise the umount will hang
54 $DMSETUP_PROG resume flakey-test > /dev/null 2>&1
55 $UMOUNT_PROG $SCRATCH_MNT > /dev/null 2>&1
56 $DMSETUP_PROG remove flakey-test > /dev/null 2>&1
57 $DMSETUP_PROG mknodes > /dev/null 2>&1
60 # _load_flakey_table <table> [lockfs]
62 # This defaults to --nolockfs, which doesn't freeze_fs() before loading the new
63 # table, so it simulates power failure.
68 [ $1 -eq $FLAKEY_DROP_WRITES ] && table="$FLAKEY_TABLE_DROP"
70 suspend_opt="--nolockfs"
71 [ $# -gt 1 ] && [ $2 -eq 1 ] && suspend_opt=""
73 $DMSETUP_PROG suspend $suspend_opt flakey-test
74 [ $? -ne 0 ] && _fatal "failed to suspend flakey-test"
76 $DMSETUP_PROG load flakey-test --table "$table"
77 [ $? -ne 0 ] && _fatal "failed to load table into flakey-test"
79 $DMSETUP_PROG resume flakey-test
80 [ $? -ne 0 ] && _fatal "failed to resumeflakey-test"
83 # Silently drop all writes and unmount/remount to simulate a crash/power
85 _flakey_drop_and_remount()
87 _load_flakey_table $FLAKEY_DROP_WRITES
90 if [ "x$1" = "xyes" ]; then
91 _check_scratch_fs $FLAKEY_DEV
94 _load_flakey_table $FLAKEY_ALLOW_WRITES