1#!/bin/ksh -p 2# 3# CDDL HEADER START 4# 5# The contents of this file are subject to the terms of the 6# Common Development and Distribution License (the "License"). 7# You may not use this file except in compliance with the License. 8# 9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10# or https://opensource.org/licenses/CDDL-1.0. 11# See the License for the specific language governing permissions 12# and limitations under the License. 13# 14# When distributing Covered Code, include this CDDL HEADER in each 15# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16# If applicable, add the following below this CDDL HEADER, with the 17# fields enclosed by brackets "[]" replaced with your own identifying 18# information: Portions Copyright [yyyy] [name of copyright owner] 19# 20# CDDL HEADER END 21# 22 23# 24# Copyright (c) 2016 by Delphix. All rights reserved. 25# 26. $STF_SUITE/include/libtest.shlib 27 28# 29# DESCRIPTION: 30# After initializing, the disk is actually initialized. 31# 32# STRATEGY: 33# 1. Create a one-disk pool. 34# 2. Initialize the disk to completion. 35# 3. Load all metaslabs and make sure that each contains at least 36# once instance of the initializing pattern (deadbeef). 37# 38 39function cleanup 40{ 41 set_tunable64 INITIALIZE_VALUE $ORIG_PATTERN 42 zpool import -d $TESTDIR $TESTPOOL 43 44 if datasetexists $TESTPOOL ; then 45 zpool destroy -f $TESTPOOL 46 fi 47 if [[ -d "$TESTDIR" ]]; then 48 rm -rf "$TESTDIR" 49 fi 50} 51log_onexit cleanup 52 53PATTERN="deadbeefdeadbeef" 54SMALLFILE="$TESTDIR/smallfile" 55 56ORIG_PATTERN=$(get_tunable INITIALIZE_VALUE) 57log_must set_tunable64 INITIALIZE_VALUE $(printf %llu 0x$PATTERN) 58 59log_must mkdir "$TESTDIR" 60log_must truncate -s $MINVDEVSIZE "$SMALLFILE" 61log_must zpool create $TESTPOOL "$SMALLFILE" 62log_must zpool initialize -w $TESTPOOL 63log_must zpool export $TESTPOOL 64 65metaslabs=0 66bs=512 67zdb -p $TESTDIR -Pme $TESTPOOL | awk '/metaslab[ ]+[0-9]+/ { print $4, $8 }' | 68while read -r offset size; do 69 log_note "offset: '$offset'" 70 log_note "size: '$size'" 71 72 metaslabs=$((metaslabs + 1)) 73 offset=$(((4 * 1024 * 1024) + 16#$offset)) 74 log_note "vdev file offset: '$offset'" 75 76 # Note we use '-t x4' instead of '-t x8' here because x8 is not 77 # a supported format on FreeBSD. 78 dd if=$SMALLFILE skip=$((offset / bs)) count=$((size / bs)) bs=$bs | 79 od -t x4 -Ad | grep -qE "deadbeef +deadbeef +deadbeef +deadbeef" || 80 log_fail "Pattern not found in metaslab free space" 81done 82 83if [[ $metaslabs -eq 0 ]]; then 84 log_fail "Did not find any metaslabs to check" 85else 86 log_pass "Initializing wrote to each metaslab" 87fi 88