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
9 local dm_backing_dev=$SCRATCH_DEV
11 local blk_dev_size=`blockdev --getsz $dm_backing_dev`
13 export DMERROR_DEV='/dev/mapper/error-test'
15 export DMLINEAR_TABLE="0 $blk_dev_size linear $dm_backing_dev 0"
17 export DMERROR_TABLE="0 $blk_dev_size error $dm_backing_dev 0"
23 _dmsetup_remove error-test
24 _dmsetup_create error-test --table "$DMLINEAR_TABLE" || \
25 _fatal "failed to create dm linear device"
30 _scratch_options mount
31 $MOUNT_PROG -t $FSTYP `_common_dev_mount_options $*` $SCRATCH_OPTIONS \
32 $DMERROR_DEV $SCRATCH_MNT
42 $DMSETUP_PROG resume error-test > /dev/null 2>&1
43 $UMOUNT_PROG $SCRATCH_MNT > /dev/null 2>&1
44 _dmsetup_remove error-test
46 unset DMERROR_DEV DMLINEAR_TABLE DMERROR_TABLE
49 _dmerror_load_error_table()
54 suspend_opt="--nolockfs"
56 if [ "$1" = "lockfs" ]; then
58 elif [ -n "$*" ]; then
62 $DMSETUP_PROG suspend $suspend_opt error-test
63 [ $? -ne 0 ] && _fail "dmsetup suspend failed"
65 $DMSETUP_PROG load error-test --table "$DMERROR_TABLE"
68 $DMSETUP_PROG resume error-test
71 [ $load_res -ne 0 ] && _fail "dmsetup failed to load error table"
72 [ $resume_res -ne 0 ] && _fail "dmsetup resume failed"
75 _dmerror_load_working_table()
80 suspend_opt="--nolockfs"
82 if [ "$1" = "lockfs" ]; then
84 elif [ -n "$*" ]; then
88 $DMSETUP_PROG suspend $suspend_opt error-test
89 [ $? -ne 0 ] && _fail "dmsetup suspend failed"
91 $DMSETUP_PROG load error-test --table "$DMLINEAR_TABLE"
94 $DMSETUP_PROG resume error-test
97 [ $load_res -ne 0 ] && _fail "dmsetup failed to load error table"
98 [ $resume_res -ne 0 ] && _fail "dmsetup resume failed"