Skip to content

Commit fa7b558

Browse files
committed
ZTS: Simplify zpool_initialize_verify_initialized
Consider the test to be a success as long as the initializing pattern is found at least once per metaslab. This indicates that at least part of the free space was initialized. Ideally we'd check that the pattern was written to all free space but that's much trickier so this check is a reasonable compromise. Using a here-string to feed the loop in this test causes an empty string to still trigger the loop so we miss the `spacemaps=0` case. Pipe into the loop instead. While here, we can use `zpool wait -t initialize $TESTPOOL` to wait for the pool to initialize. Co-authored-by: Brian Behlendorf <[email protected]> Signed-off-by: Ryan Moeller <[email protected]> Closes #11365
1 parent a103ae4 commit fa7b558

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

tests/zfs-tests/tests/functional/cli_root/zpool_initialize/zpool_initialize_verify_initialized.ksh

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
# Copyright (c) 2016 by Delphix. All rights reserved.
2525
#
2626
. $STF_SUITE/include/libtest.shlib
27-
. $STF_SUITE/tests/functional/cli_root/zpool_initialize/zpool_initialize.kshlib
2827

2928
#
3029
# DESCRIPTION:
@@ -33,8 +32,8 @@
3332
# STRATEGY:
3433
# 1. Create a one-disk pool.
3534
# 2. Initialize the disk to completion.
36-
# 3. Load all metaslabs that don't have a spacemap, and make sure the entire
37-
# metaslab has been filled with the initializing pattern (deadbeef).
35+
# 3. Load all metaslabs and make sure that each contains at least
36+
# once instance of the initializing pattern (deadbeef).
3837
#
3938

4039
function cleanup
@@ -58,32 +57,34 @@ ORIG_PATTERN=$(get_tunable INITIALIZE_VALUE)
5857
log_must set_tunable64 INITIALIZE_VALUE $(printf %llu 0x$PATTERN)
5958

6059
log_must mkdir "$TESTDIR"
61-
log_must mkfile $MINVDEVSIZE "$SMALLFILE"
60+
log_must truncate -s $MINVDEVSIZE "$SMALLFILE"
6261
log_must zpool create $TESTPOOL "$SMALLFILE"
63-
log_must zpool initialize $TESTPOOL
64-
65-
while [[ "$(initialize_progress $TESTPOOL $SMALLFILE)" -lt "100" ]]; do
66-
sleep 0.5
67-
done
68-
62+
log_must zpool initialize -w $TESTPOOL
6963
log_must zpool export $TESTPOOL
7064

71-
spacemaps=0
65+
metaslabs=0
7266
bs=512
73-
while read -r sm; do
74-
typeset offset="$(echo $sm | cut -d ' ' -f1)"
75-
typeset size="$(echo $sm | cut -d ' ' -f2)"
67+
zdb -p $TESTDIR -Pme $TESTPOOL | awk '/metaslab[ ]+[0-9]+/ { print $4, $8 }' |
68+
while read -r offset_size; do
69+
typeset offset=$(echo $offset_size | cut -d ' ' -f1)
70+
typeset size=$(echo $offset_size | cut -d ' ' -f2)
7671

77-
spacemaps=$((spacemaps + 1))
78-
offset=$(((4 * 1024 * 1024) + 16#$offset))
79-
out=$(dd if=$SMALLFILE skip=$(($offset / $bs)) \
80-
count=$(($size / $bs)) bs=$bs 2>/dev/null | od -t x8 -Ad)
81-
echo "$out" | log_must egrep "$PATTERN|\*|$size"
82-
done <<< "$(zdb -p $TESTDIR -Pme $TESTPOOL | egrep 'spacemap[ ]+0 ' | \
83-
awk '{print $4, $8}')"
72+
log_note "offset: '$offset'"
73+
log_note "size: '$size'"
74+
75+
metaslabs=$((metaslabs + 1))
76+
offset=$(((4 * 1024 * 1024) + 16#$offset))
77+
log_note "vdev file offset: '$offset'"
78+
79+
# Note we use '-t x4' instead of '-t x8' here because x8 is not
80+
# a supported format on FreeBSD.
81+
dd if=$SMALLFILE skip=$((offset / bs)) count=$((size / bs)) bs=$bs |
82+
od -t x4 -Ad | egrep -q "deadbeef +deadbeef +deadbeef +deadbeef" ||
83+
log_fail "Pattern not found in metaslab free space"
84+
done
8485

85-
if [[ $spacemaps -eq 0 ]];then
86-
log_fail "Did not find any empty space maps to check"
86+
if [[ $metaslabs -eq 0 ]]; then
87+
log_fail "Did not find any metaslabs to check"
8788
else
88-
log_pass "Initializing wrote appropriate amount to disk"
89+
log_pass "Initializing wrote to each metaslab"
8990
fi

0 commit comments

Comments
 (0)