common/dmerror: fix mount option issues
[xfstests-dev.git] / common / dmerror
1 ##/bin/bash
2 #
3 # Copyright (c) 2015 Oracle.  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 dmerror device
20
21 echo $MOUNT_OPTIONS | grep -q dax
22 if [ $? -eq 0 ]; then
23         _notrun "Cannot run tests with DAX on dmerror devices"
24 fi
25
26 _dmerror_init()
27 {
28         local dm_backing_dev=$SCRATCH_DEV
29
30         $DMSETUP_PROG remove error-test > /dev/null 2>&1
31
32         local blk_dev_size=`blockdev --getsz $dm_backing_dev`
33
34         DMERROR_DEV='/dev/mapper/error-test'
35
36         DMLINEAR_TABLE="0 $blk_dev_size linear $dm_backing_dev 0"
37
38         $DMSETUP_PROG create error-test --table "$DMLINEAR_TABLE" || \
39                 _fatal "failed to create dm linear device"
40
41         DMERROR_TABLE="0 $blk_dev_size error $dm_backing_dev 0"
42 }
43
44 _dmerror_mount()
45 {
46         _scratch_options mount
47         $MOUNT_PROG -t $FSTYP `_common_dev_mount_options $*` $SCRATCH_OPTIONS \
48                 $DMERROR_DEV $SCRATCH_MNT
49 }
50
51 _dmerror_unmount()
52 {
53         umount $SCRATCH_MNT
54 }
55
56 _dmerror_cleanup()
57 {
58         $UMOUNT_PROG $SCRATCH_MNT > /dev/null 2>&1
59         # wait for device to be fully settled so that 'dmsetup remove' doesn't
60         # fail due to EBUSY
61         $UDEV_SETTLE_PROG >/dev/null 2>&1
62         $DMSETUP_PROG remove error-test > /dev/null 2>&1
63 }
64
65 _dmerror_load_error_table()
66 {
67         suspend_opt="--nolockfs"
68
69         if [ "$1" = "lockfs" ]; then
70                 suspend_opt=""
71         elif [ -n "$*" ]; then
72                 suspend_opt="$*"
73         fi
74
75         $DMSETUP_PROG suspend $suspend_opt error-test
76         [ $? -ne 0 ] && _fail  "dmsetup suspend failed"
77
78         $DMSETUP_PROG load error-test --table "$DMERROR_TABLE"
79         [ $? -ne 0 ] && _fail "dmsetup failed to load error table"
80
81         $DMSETUP_PROG resume error-test
82         [ $? -ne 0 ] && _fail  "dmsetup resume failed"
83 }
84
85 _dmerror_load_working_table()
86 {
87         suspend_opt="--nolockfs"
88
89         if [ "$1" = "lockfs" ]; then
90                 suspend_opt=""
91         elif [ -n "$*" ]; then
92                 suspend_opt="$*"
93         fi
94
95         $DMSETUP_PROG suspend $suspend_opt error-test
96         [ $? -ne 0 ] && _fail  "dmsetup suspend failed"
97
98         $DMSETUP_PROG load error-test --table "$DMLINEAR_TABLE"
99         [ $? -ne 0 ] && _fail "dmsetup failed to load error table"
100
101         $DMSETUP_PROG resume error-test
102         [ $? -ne 0 ] && _fail  "dmsetup resume failed"
103 }