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
12 local BLK_DEV_SIZE=`blockdev --getsz $SCRATCH_DEV`
13 DELAY_DEV=/dev/mapper/delay-test
14 DELAY_TABLE="0 $BLK_DEV_SIZE delay $SCRATCH_DEV 0 0"
15 DELAY_TABLE_RDELAY="0 $BLK_DEV_SIZE delay $SCRATCH_DEV 0 10000 $SCRATCH_DEV 0 0"
16 _dmsetup_create delay-test --table "$DELAY_TABLE" || \
17 _fatal "failed to create delay device"
22 _scratch_options mount
23 $MOUNT_PROG -t $FSTYP `_common_dev_mount_options` $SCRATCH_OPTIONS \
24 $DELAY_DEV $SCRATCH_MNT
29 $UMOUNT_PROG $SCRATCH_MNT
34 # If dmsetup load fails then we need to make sure to do resume here
35 # otherwise the umount will hang
36 $DMSETUP_PROG resume delay-test > /dev/null 2>&1
37 $UMOUNT_PROG $SCRATCH_MNT > /dev/null 2>&1
38 _dmsetup_remove delay-test
41 # _load_delay_table <table> [lockfs]
43 # This defaults to --nolockfs, which doesn't freeze_fs() before loading the new
48 [ $1 -eq $DELAY_READ ] && table="$DELAY_TABLE_RDELAY"
50 suspend_opt="--nolockfs"
51 [ $# -gt 1 ] && [ $2 -eq 1 ] && suspend_opt=""
53 # run a suspend/resume cycle to avoid excessive resume delays once a
54 # delay is introduced below
55 $DMSETUP_PROG suspend $suspend_opt delay-test
56 $DMSETUP_PROG resume $suspend_opt delay-test
58 $DMSETUP_PROG suspend $suspend_opt delay-test
59 [ $? -ne 0 ] && _fatal "failed to suspend delay-test"
61 $DMSETUP_PROG load delay-test --table "$table"
62 [ $? -ne 0 ] && _fatal "failed to load table into delay-test"
64 $DMSETUP_PROG resume delay-test
65 [ $? -ne 0 ] && _fatal "failed to resume delay-test"