3 # Copyright (c) 2016 Red Hat, Inc. 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 dmdelay device
24 echo $MOUNT_OPTIONS | grep -q dax
26 _notrun "Cannot run tests with DAX on dmdelay devices"
31 local BLK_DEV_SIZE=`blockdev --getsz $SCRATCH_DEV`
32 DELAY_DEV=/dev/mapper/delay-test
33 DELAY_TABLE="0 $BLK_DEV_SIZE delay $SCRATCH_DEV 0 0"
34 DELAY_TABLE_RDELAY="0 $BLK_DEV_SIZE delay $SCRATCH_DEV 0 10000 $SCRATCH_DEV 0 0"
35 $DMSETUP_PROG create delay-test --table "$DELAY_TABLE" || \
36 _fatal "failed to create delay device"
37 $DMSETUP_PROG mknodes > /dev/null 2>&1
42 _scratch_options mount
43 $MOUNT_PROG -t $FSTYP `_common_dev_mount_options` $SCRATCH_OPTIONS \
44 $DELAY_DEV $SCRATCH_MNT
49 $UMOUNT_PROG $SCRATCH_MNT
54 # If dmsetup load fails then we need to make sure to do resume here
55 # otherwise the umount will hang
56 $DMSETUP_PROG resume delay-test > /dev/null 2>&1
57 $UMOUNT_PROG $SCRATCH_MNT > /dev/null 2>&1
58 # wait for device to be fully settled so that 'dmsetup remove' doesn't
60 $UDEV_SETTLE_PROG >/dev/null 2>&1
61 $DMSETUP_PROG remove delay-test > /dev/null 2>&1
62 $DMSETUP_PROG mknodes > /dev/null 2>&1
65 # _load_delay_table <table> [lockfs]
67 # This defaults to --nolockfs, which doesn't freeze_fs() before loading the new
72 [ $1 -eq $DELAY_READ ] && table="$DELAY_TABLE_RDELAY"
74 suspend_opt="--nolockfs"
75 [ $# -gt 1 ] && [ $2 -eq 1 ] && suspend_opt=""
77 # run a suspend/resume cycle to avoid excessive resume delays once a
78 # delay is introduced below
79 $DMSETUP_PROG suspend $suspend_opt delay-test
80 $DMSETUP_PROG resume $suspend_opt delay-test
82 $DMSETUP_PROG suspend $suspend_opt delay-test
83 [ $? -ne 0 ] && _fatal "failed to suspend delay-test"
85 $DMSETUP_PROG load delay-test --table "$table"
86 [ $? -ne 0 ] && _fatal "failed to load table into delay-test"
88 $DMSETUP_PROG resume delay-test
89 [ $? -ne 0 ] && _fatal "failed to resume delay-test"