2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2013 Fusion IO, Inc. All Rights Reserved.
5 # common functions for setting up and tearing down a dmflakey device
11 echo $MOUNT_OPTIONS | grep -q dax
13 _notrun "Cannot run tests with DAX on dmflakey devices"
18 local BLK_DEV_SIZE=`blockdev --getsz $SCRATCH_DEV`
19 FLAKEY_DEV=/dev/mapper/flakey-test
20 FLAKEY_TABLE="0 $BLK_DEV_SIZE flakey $SCRATCH_DEV 0 180 0"
21 FLAKEY_TABLE_DROP="0 $BLK_DEV_SIZE flakey $SCRATCH_DEV 0 0 180 1 drop_writes"
22 FLAKEY_TABLE_ERROR="0 $BLK_DEV_SIZE flakey $SCRATCH_DEV 0 0 180 1 error_writes"
23 _dmsetup_create flakey-test --table "$FLAKEY_TABLE" || \
24 _fatal "failed to create flakey device"
29 _scratch_options mount
30 mount -t $FSTYP $SCRATCH_OPTIONS $MOUNT_OPTIONS $FLAKEY_DEV $SCRATCH_MNT
35 $UMOUNT_PROG $SCRATCH_MNT
40 # If dmsetup load fails then we need to make sure to do resume here
41 # otherwise the umount will hang
42 $DMSETUP_PROG resume flakey-test > /dev/null 2>&1
43 $UMOUNT_PROG $SCRATCH_MNT > /dev/null 2>&1
44 _dmsetup_remove flakey-test
47 # _load_flakey_table <table> [lockfs]
49 # This defaults to --nolockfs, which doesn't freeze_fs() before loading the new
50 # table, so it simulates power failure.
54 [ $1 -eq $FLAKEY_DROP_WRITES ] && table="$FLAKEY_TABLE_DROP"
55 [ $1 -eq $FLAKEY_ERROR_WRITES ] && table="$FLAKEY_TABLE_ERROR"
57 suspend_opt="--nolockfs"
58 [ $# -gt 1 ] && [ $2 -eq 1 ] && suspend_opt=""
60 $DMSETUP_PROG suspend $suspend_opt flakey-test
61 [ $? -ne 0 ] && _fatal "failed to suspend flakey-test"
63 # There may be multiple dm targets in the table, and these dm targets
64 # will be joined by the newline ("\n"). Option --table can not cope with
65 # the multiple-targets case, so get them by reading from standard input.
66 echo -e "$table" | $DMSETUP_PROG load flakey-test
67 [ $? -ne 0 ] && _fatal "failed to load table into flakey-test"
69 $DMSETUP_PROG resume flakey-test
70 [ $? -ne 0 ] && _fatal "failed to resume flakey-test"
73 # Silently drop all writes and unmount/remount to simulate a crash/power
75 _flakey_drop_and_remount()
77 _load_flakey_table $FLAKEY_DROP_WRITES
80 if [ "x$1" = "xyes" ]; then
81 _check_scratch_fs $FLAKEY_DEV
84 _load_flakey_table $FLAKEY_ALLOW_WRITES
88 _require_flakey_with_error_writes()
92 local NAME=flakey-test
94 _require_dm_target flakey
96 SIZE=`blockdev --getsz $SCRATCH_DEV`
97 TABLE="0 $SIZE flakey $SCRATCH_DEV 0 0 180 1 error_writes"
99 _dmsetup_create $NAME --table "$TABLE" || \
100 _notrun "This test requires error_writes feature in dm-flakey"