btrfs/048: add validation of compression options
[xfstests-dev.git] / common / dmerror
1 ##/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Oracle.  All Rights Reserved.
4 #
5 # common functions for setting up and tearing down a dmerror device
6
7 echo $MOUNT_OPTIONS | grep -q dax
8 if [ $? -eq 0 ]; then
9         _notrun "Cannot run tests with DAX on dmerror devices"
10 fi
11
12 _dmerror_setup()
13 {
14         local dm_backing_dev=$SCRATCH_DEV
15
16         local blk_dev_size=`blockdev --getsz $dm_backing_dev`
17
18         DMERROR_DEV='/dev/mapper/error-test'
19
20         DMLINEAR_TABLE="0 $blk_dev_size linear $dm_backing_dev 0"
21
22         DMERROR_TABLE="0 $blk_dev_size error $dm_backing_dev 0"
23 }
24
25 _dmerror_init()
26 {
27         _dmerror_setup
28         _dmsetup_remove error-test
29         _dmsetup_create error-test --table "$DMLINEAR_TABLE" || \
30                 _fatal "failed to create dm linear device"
31 }
32
33 _dmerror_mount()
34 {
35         _scratch_options mount
36         $MOUNT_PROG -t $FSTYP `_common_dev_mount_options $*` $SCRATCH_OPTIONS \
37                 $DMERROR_DEV $SCRATCH_MNT
38 }
39
40 _dmerror_unmount()
41 {
42         umount $SCRATCH_MNT
43 }
44
45 _dmerror_cleanup()
46 {
47         $UMOUNT_PROG $SCRATCH_MNT > /dev/null 2>&1
48         _dmsetup_remove error-test
49 }
50
51 _dmerror_load_error_table()
52 {
53         suspend_opt="--nolockfs"
54
55         if [ "$1" = "lockfs" ]; then
56                 suspend_opt=""
57         elif [ -n "$*" ]; then
58                 suspend_opt="$*"
59         fi
60
61         $DMSETUP_PROG suspend $suspend_opt error-test
62         [ $? -ne 0 ] && _fail  "dmsetup suspend failed"
63
64         $DMSETUP_PROG load error-test --table "$DMERROR_TABLE"
65         [ $? -ne 0 ] && _fail "dmsetup failed to load error table"
66
67         $DMSETUP_PROG resume error-test
68         [ $? -ne 0 ] && _fail  "dmsetup resume failed"
69 }
70
71 _dmerror_load_working_table()
72 {
73         suspend_opt="--nolockfs"
74
75         if [ "$1" = "lockfs" ]; then
76                 suspend_opt=""
77         elif [ -n "$*" ]; then
78                 suspend_opt="$*"
79         fi
80
81         $DMSETUP_PROG suspend $suspend_opt error-test
82         [ $? -ne 0 ] && _fail  "dmsetup suspend failed"
83
84         $DMSETUP_PROG load error-test --table "$DMLINEAR_TABLE"
85         [ $? -ne 0 ] && _fail "dmsetup failed to load error table"
86
87         $DMSETUP_PROG resume error-test
88         [ $? -ne 0 ] && _fail  "dmsetup resume failed"
89 }