blob: 52da3b100fbe453bd6bbab711da466e5d9f32edc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
##/bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2013 Fusion IO, Inc. All Rights Reserved.
#
# common functions for setting up and tearing down a dmflakey device
FLAKEY_ALLOW_WRITES=0
FLAKEY_DROP_WRITES=1
FLAKEY_ERROR_WRITES=2
_init_flakey()
{
# Scratch device
local BLK_DEV_SIZE=`blockdev --getsz $SCRATCH_DEV`
FLAKEY_DEV=/dev/mapper/flakey-test
FLAKEY_TABLE="0 $BLK_DEV_SIZE flakey $SCRATCH_DEV 0 180 0"
FLAKEY_TABLE_DROP="0 $BLK_DEV_SIZE flakey $SCRATCH_DEV 0 0 180 1 drop_writes"
FLAKEY_TABLE_ERROR="0 $BLK_DEV_SIZE flakey $SCRATCH_DEV 0 0 180 1 error_writes"
_dmsetup_create flakey-test --table "$FLAKEY_TABLE" || \
_fatal "failed to create flakey device"
# Realtime device
if [ -n "$SCRATCH_RTDEV" ]; then
if [ -z "$NON_FLAKEY_RTDEV" ]; then
# Set up the device switch
local backing_dev="$SCRATCH_RTDEV"
export NON_FLAKEY_RTDEV="$SCRATCH_RTDEV"
SCRATCH_RTDEV=/dev/mapper/flakey-rttest
else
# Already set up; recreate tables
local backing_dev="$NON_FLAKEY_RTDEV"
fi
local BLK_DEV_SIZE=`blockdev --getsz $backing_dev`
FLAKEY_RTTABLE="0 $BLK_DEV_SIZE flakey $backing_dev 0 180 0"
FLAKEY_RTTABLE_DROP="0 $BLK_DEV_SIZE flakey $backing_dev 0 0 180 1 drop_writes"
FLAKEY_RTTABLE_ERROR="0 $BLK_DEV_SIZE flakey $backing_dev 0 0 180 1 error_writes"
_dmsetup_create flakey-rttest --table "$FLAKEY_RTTABLE" || \
_fatal "failed to create flakey rt device"
fi
# External log device
if [ -n "$SCRATCH_LOGDEV" ]; then
if [ -z "$NON_FLAKEY_LOGDEV" ]; then
# Set up the device switch
local backing_dev="$SCRATCH_LOGDEV"
export NON_FLAKEY_LOGDEV="$SCRATCH_LOGDEV"
SCRATCH_LOGDEV=/dev/mapper/flakey-logtest
else
# Already set up; recreate tables
local backing_dev="$NON_FLAKEY_LOGDEV"
fi
local BLK_DEV_SIZE=`blockdev --getsz $backing_dev`
FLAKEY_LOGTABLE="0 $BLK_DEV_SIZE flakey $backing_dev 0 180 0"
FLAKEY_LOGTABLE_DROP="0 $BLK_DEV_SIZE flakey $backing_dev 0 0 180 1 drop_writes"
FLAKEY_LOGTABLE_ERROR="0 $BLK_DEV_SIZE flakey $backing_dev 0 0 180 1 error_writes"
_dmsetup_create flakey-logtest --table "$FLAKEY_LOGTABLE" || \
_fatal "failed to create flakey log device"
fi
}
_mount_flakey()
{
_scratch_options mount
mount -t $FSTYP $SCRATCH_OPTIONS $MOUNT_OPTIONS $FLAKEY_DEV $SCRATCH_MNT
}
_unmount_flakey()
{
$UMOUNT_PROG $SCRATCH_MNT
}
_cleanup_flakey()
{
# If dmsetup load fails then we need to make sure to do resume here
# otherwise the umount will hang
test -n "$NON_FLAKEY_LOGDEV" && $DMSETUP_PROG resume flakey-logtest &> /dev/null
test -n "$NON_FLAKEY_RTDEV" && $DMSETUP_PROG resume flakey-rttest &> /dev/null
$DMSETUP_PROG resume flakey-test > /dev/null 2>&1
$UMOUNT_PROG $SCRATCH_MNT > /dev/null 2>&1
_dmsetup_remove flakey-test
test -n "$NON_FLAKEY_LOGDEV" && _dmsetup_remove flakey-logtest
test -n "$NON_FLAKEY_RTDEV" && _dmsetup_remove flakey-rttest
if [ -n "$NON_FLAKEY_LOGDEV" ]; then
SCRATCH_LOGDEV="$NON_FLAKEY_LOGDEV"
unset NON_FLAKEY_LOGDEV
fi
if [ -n "$NON_FLAKEY_RTDEV" ]; then
SCRATCH_RTDEV="$NON_FLAKEY_RTDEV"
unset NON_FLAKEY_RTDEV
fi
}
# _load_flakey_table <table> [lockfs]
#
# This defaults to --nolockfs, which doesn't freeze_fs() before loading the new
# table, so it simulates power failure.
_load_flakey_table()
{
case "$1" in
"$FLAKEY_DROP_WRITES")
table="$FLAKEY_TABLE_DROP"
logtable="$FLAKEY_LOGTABLE_DROP"
rttable="$FLAKEY_RTTABLE_DROP"
;;
"$FLAKEY_ERROR_WRITES")
table="$FLAKEY_TABLE_ERROR"
logtable="$FLAKEY_LOGTABLE_ERROR"
rttable="$FLAKEY_RTTABLE_ERROR"
;;
*)
table="$FLAKEY_TABLE"
logtable="$FLAKEY_LOGTABLE"
rttable="$FLAKEY_RTTABLE"
;;
esac
suspend_opt="--nolockfs"
[ $# -gt 1 ] && [ $2 -eq 1 ] && suspend_opt=""
# Suspend the scratch device before the log and realtime devices so
# that the kernel can freeze and flush the filesystem if the caller
# wanted a freeze.
$DMSETUP_PROG suspend $suspend_opt flakey-test
[ $? -ne 0 ] && _fatal "failed to suspend flakey-test"
if [ -n "$NON_FLAKEY_RTDEV" ]; then
$DMSETUP_PROG suspend $suspend_opt flakey-rttest
[ $? -ne 0 ] && _fatal "failed to suspend flakey-rttest"
fi
if [ -n "$NON_FLAKEY_LOGDEV" ]; then
$DMSETUP_PROG suspend $suspend_opt flakey-logtest
[ $? -ne 0 ] && _fatal "failed to suspend flakey-logtest"
fi
# There may be multiple dm targets in the table, and these dm targets
# will be joined by the newline ("\n"). Option --table can not cope with
# the multiple-targets case, so get them by reading from standard input.
echo -e "$table" | $DMSETUP_PROG load flakey-test
[ $? -ne 0 ] && _fatal "failed to load table into flakey-test"
if [ -n "$NON_FLAKEY_RTDEV" ]; then
echo -e "$rttable" | $DMSETUP_PROG load flakey-rttest
[ $? -ne 0 ] && _fatal "failed to load table into flakey-rttest"
fi
if [ -n "$NON_FLAKEY_LOGDEV" ]; then
echo -e "$logtable" | $DMSETUP_PROG load flakey-logtest
[ $? -ne 0 ] && _fatal "failed to load table into flakey-logtest"
fi
# Resume devices in the opposite order that we suspended them.
if [ -n "$NON_FLAKEY_LOGDEV" ]; then
$DMSETUP_PROG resume flakey-logtest
[ $? -ne 0 ] && _fatal "failed to resume flakey-logtest"
fi
if [ -n "$NON_FLAKEY_RTDEV" ]; then
$DMSETUP_PROG resume flakey-rttest
[ $? -ne 0 ] && _fatal "failed to resume flakey-rttest"
fi
$DMSETUP_PROG resume flakey-test
[ $? -ne 0 ] && _fatal "failed to resume flakey-test"
}
# Silently drop all writes and unmount/remount to simulate a crash/power
# failure.
_flakey_drop_and_remount()
{
_load_flakey_table $FLAKEY_DROP_WRITES
_unmount_flakey
if [ "x$1" = "xyes" ]; then
_check_scratch_fs $FLAKEY_DEV
fi
_load_flakey_table $FLAKEY_ALLOW_WRITES
_mount_flakey
}
_require_flakey_with_error_writes()
{
local SIZE
local TABLE
local NAME=flakey-test
_require_dm_target flakey
SIZE=`blockdev --getsz $SCRATCH_DEV`
TABLE="0 $SIZE flakey $SCRATCH_DEV 0 0 180 1 error_writes"
_dmsetup_create $NAME --table "$TABLE" || \
_notrun "This test requires error_writes feature in dm-flakey"
_cleanup_flakey
}
|