2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Red Hat, Inc. All Rights Reserved.
5 # common functions for setting up and tearing down a dmdelay device
10 echo $MOUNT_OPTIONS | grep -q dax
12 _notrun "Cannot run tests with DAX on dmdelay devices"
17 local BLK_DEV_SIZE=`blockdev --getsz $SCRATCH_DEV`
18 DELAY_DEV=/dev/mapper/delay-test
19 DELAY_TABLE="0 $BLK_DEV_SIZE delay $SCRATCH_DEV 0 0"
20 DELAY_TABLE_RDELAY="0 $BLK_DEV_SIZE delay $SCRATCH_DEV 0 10000 $SCRATCH_DEV 0 0"
21 _dmsetup_create delay-test --table "$DELAY_TABLE" || \
22 _fatal "failed to create delay device"
27 _scratch_options mount
28 $MOUNT_PROG -t $FSTYP `_common_dev_mount_options` $SCRATCH_OPTIONS \
29 $DELAY_DEV $SCRATCH_MNT
34 $UMOUNT_PROG $SCRATCH_MNT
39 # If dmsetup load fails then we need to make sure to do resume here
40 # otherwise the umount will hang
41 $DMSETUP_PROG resume delay-test > /dev/null 2>&1
42 $UMOUNT_PROG $SCRATCH_MNT > /dev/null 2>&1
43 _dmsetup_remove delay-test
46 # _load_delay_table <table> [lockfs]
48 # This defaults to --nolockfs, which doesn't freeze_fs() before loading the new
53 [ $1 -eq $DELAY_READ ] && table="$DELAY_TABLE_RDELAY"
55 suspend_opt="--nolockfs"
56 [ $# -gt 1 ] && [ $2 -eq 1 ] && suspend_opt=""
58 # run a suspend/resume cycle to avoid excessive resume delays once a
59 # delay is introduced below
60 $DMSETUP_PROG suspend $suspend_opt delay-test
61 $DMSETUP_PROG resume $suspend_opt delay-test
63 $DMSETUP_PROG suspend $suspend_opt delay-test
64 [ $? -ne 0 ] && _fatal "failed to suspend delay-test"
66 $DMSETUP_PROG load delay-test --table "$table"
67 [ $? -ne 0 ] && _fatal "failed to load table into delay-test"
69 $DMSETUP_PROG resume delay-test
70 [ $? -ne 0 ] && _fatal "failed to resume delay-test"