2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Oracle. All Rights Reserved.
5 # common functions for setting up and tearing down a dmerror device
7 echo $MOUNT_OPTIONS | grep -q dax
9 _notrun "Cannot run tests with DAX on dmerror devices"
14 local dm_backing_dev=$SCRATCH_DEV
16 local blk_dev_size=`blockdev --getsz $dm_backing_dev`
18 DMERROR_DEV='/dev/mapper/error-test'
20 DMLINEAR_TABLE="0 $blk_dev_size linear $dm_backing_dev 0"
22 DMERROR_TABLE="0 $blk_dev_size error $dm_backing_dev 0"
28 _dmsetup_remove error-test
29 _dmsetup_create error-test --table "$DMLINEAR_TABLE" || \
30 _fatal "failed to create dm linear device"
35 _scratch_options mount
36 $MOUNT_PROG -t $FSTYP `_common_dev_mount_options $*` $SCRATCH_OPTIONS \
37 $DMERROR_DEV $SCRATCH_MNT
47 $UMOUNT_PROG $SCRATCH_MNT > /dev/null 2>&1
48 _dmsetup_remove error-test
51 _dmerror_load_error_table()
53 suspend_opt="--nolockfs"
55 if [ "$1" = "lockfs" ]; then
57 elif [ -n "$*" ]; then
61 $DMSETUP_PROG suspend $suspend_opt error-test
62 [ $? -ne 0 ] && _fail "dmsetup suspend failed"
64 $DMSETUP_PROG load error-test --table "$DMERROR_TABLE"
65 [ $? -ne 0 ] && _fail "dmsetup failed to load error table"
67 $DMSETUP_PROG resume error-test
68 [ $? -ne 0 ] && _fail "dmsetup resume failed"
71 _dmerror_load_working_table()
73 suspend_opt="--nolockfs"
75 if [ "$1" = "lockfs" ]; then
77 elif [ -n "$*" ]; then
81 $DMSETUP_PROG suspend $suspend_opt error-test
82 [ $? -ne 0 ] && _fail "dmsetup suspend failed"
84 $DMSETUP_PROG load error-test --table "$DMLINEAR_TABLE"
85 [ $? -ne 0 ] && _fail "dmsetup failed to load error table"
87 $DMSETUP_PROG resume error-test
88 [ $? -ne 0 ] && _fail "dmsetup resume failed"