blob: fb7b3752ac500d53b7d2b10f94d035505db1738b (
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
|
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#
# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
#
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/redundancy/redundancy.cfg
function cleanup
{
if poolexists $TESTPOOL; then
destroy_pool $TESTPOOL
fi
typeset dir
for dir in $TESTDIR $BASEDIR; do
if [[ -d $dir ]]; then
log_must rm -rf $dir
fi
done
}
#
# Get random number between min and max number.
#
# $1 Minimal value
# $2 Maximal value
#
function random
{
typeset -i min=$1
typeset -i max=$2
typeset -i value
while true; do
((value = RANDOM % (max + 1)))
if ((value >= min)); then
break
fi
done
echo $value
}
#
# Record the directories construction and checksum all the files which reside
# within the specified pool
#
# $1 The specified pool
# $2 The file which save the record.
#
function record_data
{
typeset pool=$1
typeset recordfile=$2
[[ -z $pool ]] && log_fail "No specified pool."
[[ -f $recordfile ]] && log_must rm -f $recordfile
typeset mntpnt
mntpnt=$(get_prop mountpoint $pool)
log_must eval "du -a $mntpnt > $recordfile 2>&1"
#
# When the data was damaged, checksum is failing and return 1
# So, will not use log_must
#
find $mntpnt -type f -exec cksum {} + >> $recordfile 2>&1
}
#
# Create test pool and fill with files and directories.
#
# $1 pool name
# $2 pool type
# $3 virtual devices number
#
function setup_test_env
{
typeset pool=$1
typeset keyword=$2
typeset -i vdev_cnt=$3
typeset vdevs
typeset -i i=0
while (( i < vdev_cnt )); do
vdevs="$vdevs $BASEDIR/vdev$i"
((i += 1))
done
if [[ ! -d $BASEDIR ]]; then
log_must mkdir $BASEDIR
fi
if poolexists $pool ; then
destroy_pool $pool
fi
log_must mkfile $MINVDEVSIZE $vdevs
log_must zpool create -m $TESTDIR $pool $keyword $vdevs
log_note "Filling up the filesystem ..."
typeset -i ret=0
typeset -i i=0
typeset file=$TESTDIR/file
while true ; do
file_write -o create -f $file.$i \
-b $BLOCKSZ -c $NUM_WRITES
ret=$?
(( $ret != 0 )) && break
(( i = i + 1 ))
done
(($ret != 28 )) && log_note "file_write return value($ret) is unexpected."
record_data $TESTPOOL $PRE_RECORD_FILE
}
#
# Check pool status is healthy
#
# $1 pool
#
function is_healthy
{
typeset pool=$1
typeset healthy_output="pool '$pool' is healthy"
typeset real_output=$(zpool status -x $pool)
if [[ "$real_output" == "$healthy_output" ]]; then
return 0
else
typeset -i ret
zpool status -x $pool | grep "state:" | \
grep "FAULTED" >/dev/null 2>&1
ret=$?
(( $ret == 0 )) && return 1
typeset l_scan
typeset errnum
l_scan=$(zpool status -x $pool | grep "scan:")
l_scan=${l_scan##*"with"}
errnum=$(echo $l_scan | awk '{print $1}')
return $errnum
fi
}
#
# Check pool data is valid
#
# $1 pool
#
function is_data_valid
{
typeset pool=$1
record_data $pool $PST_RECORD_FILE
if ! diff $PRE_RECORD_FILE $PST_RECORD_FILE > /dev/null 2>&1; then
return 1
fi
return 0
}
#
# Get the specified count devices name
#
# $1 pool name
# $2 devices count
#
function get_vdevs #pool cnt
{
typeset pool=$1
typeset -i cnt=$2
typeset all_devs=$(zpool iostat -v $pool | awk '{print $1}'| \
egrep -v "^pool$|^capacity$|^mirror$|^raidz1$|^raidz2$|---" | \
egrep -v "/old$|^$pool$")
typeset -i i=0
typeset vdevs
while ((i < cnt)); do
typeset dev=$(echo $all_devs | awk '{print $1}')
eval all_devs=\${all_devs##*$dev}
vdevs="$dev $vdevs"
((i += 1))
done
echo "$vdevs"
}
#
# Synchronize all the data in pool
#
# $1 pool name
#
function sync_pool #pool
{
typeset pool=$1
log_must sync
log_must sleep 2
# Flush all the pool data.
typeset -i ret
zpool scrub $pool >/dev/null 2>&1
ret=$?
(( $ret != 0 )) && \
log_fail "zpool scrub $pool failed."
while ! is_pool_scrubbed $pool; do
if is_pool_resilvered $pool ; then
log_fail "$pool should not be resilver completed."
fi
log_must sleep 2
done
}
#
# Create and replace the same name virtual device files
#
# $1 pool name
# $2-n virtual device files
#
function replace_missing_devs
{
typeset pool=$1
shift
typeset vdev
for vdev in $@; do
log_must mkfile $MINVDEVSIZE $vdev
log_must zpool replace -f $pool $vdev $vdev
while true; do
if ! is_pool_resilvered $pool ; then
log_must sleep 2
else
break
fi
done
done
}
#
# Damage the pool's virtual device files.
#
# $1 pool name
# $2 Failing devices count
# $3 damage vdevs method, if not null, we keep
# the label for the vdevs
#
function damage_devs
{
typeset pool=$1
typeset -i cnt=$2
typeset label="$3"
typeset vdevs
typeset -i bs_count=$((64 * 1024))
vdevs=$(get_vdevs $pool $cnt)
typeset dev
if [[ -n $label ]]; then
for dev in $vdevs; do
dd if=/dev/zero of=$dev seek=512 bs=1024 \
count=$bs_count conv=notrunc >/dev/null 2>&1
done
else
for dev in $vdevs; do
dd if=/dev/zero of=$dev bs=1024 count=$bs_count \
conv=notrunc >/dev/null 2>&1
done
fi
sync_pool $pool
}
#
# Clear errors in the pool caused by data corruptions
#
# $1 pool name
#
function clear_errors
{
typeset pool=$1
log_must zpool clear $pool
if ! is_healthy $pool ; then
log_note "$pool should be healthy."
return 1
fi
if ! is_data_valid $pool ; then
log_note "Data should be valid in $pool."
return 1
fi
return 0
}
#
# Remove the specified pool's virtual device files
#
# $1 Pool name
# $2 Missing devices count
#
function remove_devs
{
typeset pool=$1
typeset -i cnt=$2
typeset vdevs
vdevs=$(get_vdevs $pool $cnt)
log_must rm -f $vdevs
sync_pool $pool
}
#
# Recover the bad or missing device files in the pool
#
# $1 Pool name
# $2 Missing devices count
#
function recover_bad_missing_devs
{
typeset pool=$1
typeset -i cnt=$2
typeset vdevs
vdevs=$(get_vdevs $pool $cnt)
replace_missing_devs $pool $vdevs
if ! is_healthy $pool ; then
log_note "$pool should be healthy."
return 1
fi
if ! is_data_valid $pool ; then
log_note "Data should be valid in $pool."
return 1
fi
return 0
}
|