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
25 echo $MOUNT_OPTIONS | grep -q dax
27 _notrun "Cannot run tests with DAX on dmflakey devices"
32 local BLK_DEV_SIZE=`blockdev --getsz $SCRATCH_DEV`
33 FLAKEY_DEV=/dev/mapper/flakey-test
34 FLAKEY_TABLE="0 $BLK_DEV_SIZE flakey $SCRATCH_DEV 0 180 0"
35 FLAKEY_TABLE_DROP="0 $BLK_DEV_SIZE flakey $SCRATCH_DEV 0 0 180 1 drop_writes"
36 FLAKEY_TABLE_ERROR="0 $BLK_DEV_SIZE flakey $SCRATCH_DEV 0 0 180 1 error_writes"
37 $DMSETUP_PROG create flakey-test --table "$FLAKEY_TABLE" || \
38 _fatal "failed to create flakey device"
39 $DMSETUP_PROG mknodes > /dev/null 2>&1
44 _scratch_options mount
45 mount -t $FSTYP $SCRATCH_OPTIONS $MOUNT_OPTIONS $FLAKEY_DEV $SCRATCH_MNT
50 $UMOUNT_PROG $SCRATCH_MNT
55 # If dmsetup load fails then we need to make sure to do resume here
56 # otherwise the umount will hang
57 $DMSETUP_PROG resume flakey-test > /dev/null 2>&1
58 $UMOUNT_PROG $SCRATCH_MNT > /dev/null 2>&1
59 # wait for device to be fully settled so that 'dmsetup remove' doesn't
61 $UDEV_SETTLE_PROG >/dev/null 2>&1
62 $DMSETUP_PROG remove flakey-test > /dev/null 2>&1
63 $DMSETUP_PROG mknodes > /dev/null 2>&1
66 # _load_flakey_table <table> [lockfs]
68 # This defaults to --nolockfs, which doesn't freeze_fs() before loading the new
69 # table, so it simulates power failure.
73 [ $1 -eq $FLAKEY_DROP_WRITES ] && table="$FLAKEY_TABLE_DROP"
74 [ $1 -eq $FLAKEY_ERROR_WRITES ] && table="$FLAKEY_TABLE_ERROR"
76 suspend_opt="--nolockfs"
77 [ $# -gt 1 ] && [ $2 -eq 1 ] && suspend_opt=""
79 $DMSETUP_PROG suspend $suspend_opt flakey-test
80 [ $? -ne 0 ] && _fatal "failed to suspend flakey-test"
82 # There may be multiple dm targets in the table, and these dm targets
83 # will be joined by the newline ("\n"). Option --table can not cope with
84 # the multiple-targets case, so get them by reading from standard input.
85 echo -e "$table" | $DMSETUP_PROG load flakey-test
86 [ $? -ne 0 ] && _fatal "failed to load table into flakey-test"
88 $DMSETUP_PROG resume flakey-test
89 [ $? -ne 0 ] && _fatal "failed to resume flakey-test"
92 # Silently drop all writes and unmount/remount to simulate a crash/power
94 _flakey_drop_and_remount()
96 _load_flakey_table $FLAKEY_DROP_WRITES
99 if [ "x$1" = "xyes" ]; then
100 _check_scratch_fs $FLAKEY_DEV
103 _load_flakey_table $FLAKEY_ALLOW_WRITES
107 _require_flakey_with_error_writes()
111 local NAME=flakey-test
113 _require_dm_target flakey
115 SIZE=`blockdev --getsz $SCRATCH_DEV`
116 TABLE="0 $SIZE flakey $SCRATCH_DEV 0 0 180 1 error_writes"
118 $DMSETUP_PROG create $NAME --table "$TABLE" >/dev/null 2>&1
119 if [ $? -ne 0 ]; then
120 _notrun "This test requires error_writes feature in dm-flakey"
122 $DMSETUP_PROG mknodes >/dev/null 2>&1