From 2844ad60d41717f4713ed01df2d46bc12f590ddd Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Fri, 18 Dec 2020 08:42:59 -0800 Subject: 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 Signed-off-by: Ryan Moeller Closes #11365 --- .../zpool_initialize_verify_initialized.ksh | 49 +++++++++++----------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_initialize/zpool_initialize_verify_initialized.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_initialize/zpool_initialize_verify_initialized.ksh index 6a8f7d49f..f774970a7 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_initialize/zpool_initialize_verify_initialized.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_initialize/zpool_initialize_verify_initialized.ksh @@ -24,7 +24,6 @@ # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib -. $STF_SUITE/tests/functional/cli_root/zpool_initialize/zpool_initialize.kshlib # # DESCRIPTION: @@ -33,8 +32,8 @@ # STRATEGY: # 1. Create a one-disk pool. # 2. Initialize the disk to completion. -# 3. Load all metaslabs that don't have a spacemap, and make sure the entire -# metaslab has been filled with the initializing pattern (deadbeef). +# 3. Load all metaslabs and make sure that each contains at least +# once instance of the initializing pattern (deadbeef). # function cleanup @@ -58,32 +57,34 @@ ORIG_PATTERN=$(get_tunable INITIALIZE_VALUE) log_must set_tunable64 INITIALIZE_VALUE $(printf %llu 0x$PATTERN) log_must mkdir "$TESTDIR" -log_must mkfile $MINVDEVSIZE "$SMALLFILE" +log_must truncate -s $MINVDEVSIZE "$SMALLFILE" log_must zpool create $TESTPOOL "$SMALLFILE" -log_must zpool initialize $TESTPOOL - -while [[ "$(initialize_progress $TESTPOOL $SMALLFILE)" -lt "100" ]]; do - sleep 0.5 -done - +log_must zpool initialize -w $TESTPOOL log_must zpool export $TESTPOOL -spacemaps=0 +metaslabs=0 bs=512 -while read -r sm; do - typeset offset="$(echo $sm | cut -d ' ' -f1)" - typeset size="$(echo $sm | cut -d ' ' -f2)" +zdb -p $TESTDIR -Pme $TESTPOOL | awk '/metaslab[ ]+[0-9]+/ { print $4, $8 }' | +while read -r offset_size; do + typeset offset=$(echo $offset_size | cut -d ' ' -f1) + typeset size=$(echo $offset_size | cut -d ' ' -f2) - spacemaps=$((spacemaps + 1)) - offset=$(((4 * 1024 * 1024) + 16#$offset)) - out=$(dd if=$SMALLFILE skip=$(($offset / $bs)) \ - count=$(($size / $bs)) bs=$bs 2>/dev/null | od -t x8 -Ad) - echo "$out" | log_must egrep "$PATTERN|\*|$size" -done <<< "$(zdb -p $TESTDIR -Pme $TESTPOOL | egrep 'spacemap[ ]+0 ' | \ - awk '{print $4, $8}')" + log_note "offset: '$offset'" + log_note "size: '$size'" + + metaslabs=$((metaslabs + 1)) + offset=$(((4 * 1024 * 1024) + 16#$offset)) + log_note "vdev file offset: '$offset'" + + # Note we use '-t x4' instead of '-t x8' here because x8 is not + # a supported format on FreeBSD. + dd if=$SMALLFILE skip=$((offset / bs)) count=$((size / bs)) bs=$bs | + od -t x4 -Ad | egrep -q "deadbeef +deadbeef +deadbeef +deadbeef" || + log_fail "Pattern not found in metaslab free space" +done -if [[ $spacemaps -eq 0 ]];then - log_fail "Did not find any empty space maps to check" +if [[ $metaslabs -eq 0 ]]; then + log_fail "Did not find any metaslabs to check" else - log_pass "Initializing wrote appropriate amount to disk" + log_pass "Initializing wrote to each metaslab" fi -- cgit v1.2.3