3 # Copyright (c) 2015 Oracle. 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 dmerror device
21 echo $MOUNT_OPTIONS | grep -q dax
23 _notrun "Cannot run tests with DAX on dmerror devices"
28 local dm_backing_dev=$SCRATCH_DEV
30 local blk_dev_size=`blockdev --getsz $dm_backing_dev`
32 DMERROR_DEV='/dev/mapper/error-test'
34 DMLINEAR_TABLE="0 $blk_dev_size linear $dm_backing_dev 0"
36 DMERROR_TABLE="0 $blk_dev_size error $dm_backing_dev 0"
42 $DMSETUP_PROG remove error-test > /dev/null 2>&1
43 $DMSETUP_PROG create error-test --table "$DMLINEAR_TABLE" || \
44 _fatal "failed to create dm linear device"
49 _scratch_options mount
50 $MOUNT_PROG -t $FSTYP `_common_dev_mount_options $*` $SCRATCH_OPTIONS \
51 $DMERROR_DEV $SCRATCH_MNT
61 $UMOUNT_PROG $SCRATCH_MNT > /dev/null 2>&1
62 # wait for device to be fully settled so that 'dmsetup remove' doesn't
64 $UDEV_SETTLE_PROG >/dev/null 2>&1
65 $DMSETUP_PROG remove error-test > /dev/null 2>&1
68 _dmerror_load_error_table()
70 suspend_opt="--nolockfs"
72 if [ "$1" = "lockfs" ]; then
74 elif [ -n "$*" ]; then
78 $DMSETUP_PROG suspend $suspend_opt error-test
79 [ $? -ne 0 ] && _fail "dmsetup suspend failed"
81 $DMSETUP_PROG load error-test --table "$DMERROR_TABLE"
82 [ $? -ne 0 ] && _fail "dmsetup failed to load error table"
84 $DMSETUP_PROG resume error-test
85 [ $? -ne 0 ] && _fail "dmsetup resume failed"
88 _dmerror_load_working_table()
90 suspend_opt="--nolockfs"
92 if [ "$1" = "lockfs" ]; then
94 elif [ -n "$*" ]; then
98 $DMSETUP_PROG suspend $suspend_opt error-test
99 [ $? -ne 0 ] && _fail "dmsetup suspend failed"
101 $DMSETUP_PROG load error-test --table "$DMLINEAR_TABLE"
102 [ $? -ne 0 ] && _fail "dmsetup failed to load error table"
104 $DMSETUP_PROG resume error-test
105 [ $? -ne 0 ] && _fail "dmsetup resume failed"