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 $DMSETUP_PROG remove error-test > /dev/null 2>&1
32 local blk_dev_size=`blockdev --getsz $dm_backing_dev`
34 DMERROR_DEV='/dev/mapper/error-test'
36 DMLINEAR_TABLE="0 $blk_dev_size linear $dm_backing_dev 0"
38 $DMSETUP_PROG create error-test --table "$DMLINEAR_TABLE" || \
39 _fatal "failed to create dm linear device"
41 DMERROR_TABLE="0 $blk_dev_size error $dm_backing_dev 0"
46 _scratch_options mount
47 $MOUNT_PROG -t $FSTYP `_common_dev_mount_options $*` $SCRATCH_OPTIONS \
48 $DMERROR_DEV $SCRATCH_MNT
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 error-test > /dev/null 2>&1
65 _dmerror_load_error_table()
67 suspend_opt="--nolockfs"
69 if [ "$1" = "lockfs" ]; then
71 elif [ -n "$*" ]; then
75 $DMSETUP_PROG suspend $suspend_opt error-test
76 [ $? -ne 0 ] && _fail "dmsetup suspend failed"
78 $DMSETUP_PROG load error-test --table "$DMERROR_TABLE"
79 [ $? -ne 0 ] && _fail "dmsetup failed to load error table"
81 $DMSETUP_PROG resume error-test
82 [ $? -ne 0 ] && _fail "dmsetup resume failed"
85 _dmerror_load_working_table()
87 suspend_opt="--nolockfs"
89 if [ "$1" = "lockfs" ]; then
91 elif [ -n "$*" ]; then
95 $DMSETUP_PROG suspend $suspend_opt error-test
96 [ $? -ne 0 ] && _fail "dmsetup suspend failed"
98 $DMSETUP_PROG load error-test --table "$DMLINEAR_TABLE"
99 [ $? -ne 0 ] && _fail "dmsetup failed to load error table"
101 $DMSETUP_PROG resume error-test
102 [ $? -ne 0 ] && _fail "dmsetup resume failed"