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 http://www.opensolaris.org/os/licensing. 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. $STF_SUITE/tests/functional/cli_root/zpool_initialize/zpool_initialize.kshlib 28 29# 30# DESCRIPTION: 31# After initializing, the disk is actually initialized. 32# 33# STRATEGY: 34# 1. Create a one-disk pool. 35# 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). 38# 39 40function cleanup 41{ 42 set_tunable64 INITIALIZE_VALUE $ORIG_PATTERN 43 zpool import -d $TESTDIR $TESTPOOL 44 45 if datasetexists $TESTPOOL ; then 46 zpool destroy -f $TESTPOOL 47 fi 48 if [[ -d "$TESTDIR" ]]; then 49 rm -rf "$TESTDIR" 50 fi 51} 52log_onexit cleanup 53 54PATTERN="deadbeefdeadbeef" 55SMALLFILE="$TESTDIR/smallfile" 56 57ORIG_PATTERN=$(get_tunable INITIALIZE_VALUE) 58log_must set_tunable64 INITIALIZE_VALUE $(printf %llu 0x$PATTERN) 59 60log_must mkdir "$TESTDIR" 61log_must mkfile $MINVDEVSIZE "$SMALLFILE" 62log_must zpool create $TESTPOOL "$SMALLFILE" 63log_must zpool initialize $TESTPOOL 64 65while [[ "$(initialize_progress $TESTPOOL $SMALLFILE)" -lt "100" ]]; do 66 sleep 0.5 67done 68 69log_must zpool export $TESTPOOL 70 71spacemaps=0 72bs=512 73while read -r sm; do 74 typeset offset="$(echo $sm | cut -d ' ' -f1)" 75 typeset size="$(echo $sm | cut -d ' ' -f2)" 76 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" 82done <<< "$(zdb -p $TESTDIR -Pme $TESTPOOL | egrep 'spacemap[ ]+0 ' | \ 83 awk '{print $4, $8}')" 84 85if [[ $spacemaps -eq 0 ]];then 86 log_fail "Did not find any empty space maps to check" 87else 88 log_pass "Initializing wrote appropriate amount to disk" 89fi 90