dmflakey: don't run for dax mounts
[xfstests-dev.git] / common / dmflakey
1 ##/bin/bash
2 #
3 # Copyright (c) 2013 Fusion IO, Inc.  All Rights Reserved.
4 #
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.
8 #
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.
13 #
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
17 #
18 #
19 # common functions for setting up and tearing down a dmflakey device
20
21 FLAKEY_ALLOW_WRITES=0
22 FLAKEY_DROP_WRITES=1
23
24 echo $MOUNT_OPTIONS | grep -q dax
25 if [ $? -eq 0 ]; then
26         _notrun "Cannot run tests with DAX on dmflakey devices"
27 fi
28
29 _init_flakey()
30 {
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
38 }
39
40 _mount_flakey()
41 {
42         mount -t $FSTYP $MOUNT_OPTIONS $FLAKEY_DEV $SCRATCH_MNT
43 }
44
45 _unmount_flakey()
46 {
47         $UMOUNT_PROG $SCRATCH_MNT
48 }
49
50 _cleanup_flakey()
51 {
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
58 }
59
60 # _load_flakey_table <table> [lockfs]
61 #
62 # This defaults to --nolockfs, which doesn't freeze_fs() before loading the new
63 # table, so it simulates power failure.
64 _load_flakey_table()
65 {
66
67         table="$FLAKEY_TABLE"
68         [ $1 -eq $FLAKEY_DROP_WRITES ] && table="$FLAKEY_TABLE_DROP"
69
70         suspend_opt="--nolockfs"
71         [ $# -gt 1 ] && [ $2 -eq 1 ] && suspend_opt=""
72
73         $DMSETUP_PROG suspend $suspend_opt flakey-test
74         [ $? -ne 0 ] && _fatal "failed to suspend flakey-test"
75
76         $DMSETUP_PROG load flakey-test --table "$table"
77         [ $? -ne 0 ] && _fatal "failed to load table into flakey-test"
78
79         $DMSETUP_PROG resume flakey-test
80         [ $? -ne 0 ] && _fatal  "failed to resumeflakey-test"
81 }
82
83 # Silently drop all writes and unmount/remount to simulate a crash/power
84 # failure.
85 _flakey_drop_and_remount()
86 {
87         _load_flakey_table $FLAKEY_DROP_WRITES
88         _unmount_flakey
89
90         if [ "x$1" = "xyes" ]; then
91                 _check_scratch_fs $FLAKEY_DEV
92         fi
93
94         _load_flakey_table $FLAKEY_ALLOW_WRITES
95         _mount_flakey
96 }