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 DMERROR_DEV='/dev/mapper/error-test'
15 DMLINEAR_TABLE="0 $blk_dev_size linear $dm_backing_dev 0"
17 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
47 _dmerror_load_error_table()
52 suspend_opt="--nolockfs"
54 if [ "$1" = "lockfs" ]; then
56 elif [ -n "$*" ]; then
60 $DMSETUP_PROG suspend $suspend_opt error-test
61 [ $? -ne 0 ] && _fail "dmsetup suspend failed"
63 $DMSETUP_PROG load error-test --table "$DMERROR_TABLE"
66 $DMSETUP_PROG resume error-test
69 [ $load_res -ne 0 ] && _fail "dmsetup failed to load error table"
70 [ $resume_res -ne 0 ] && _fail "dmsetup resume failed"
73 _dmerror_load_working_table()
78 suspend_opt="--nolockfs"
80 if [ "$1" = "lockfs" ]; then
82 elif [ -n "$*" ]; then
86 $DMSETUP_PROG suspend $suspend_opt error-test
87 [ $? -ne 0 ] && _fail "dmsetup suspend failed"
89 $DMSETUP_PROG load error-test --table "$DMLINEAR_TABLE"
92 $DMSETUP_PROG resume error-test
95 [ $load_res -ne 0 ] && _fail "dmsetup failed to load error table"
96 [ $resume_res -ne 0 ] && _fail "dmsetup resume failed"