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 mdb -kwe "zfs_initialize_value/Z $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 53PATTERN="deadbeefdeadbeef" 54SMALLFILE="$TESTDIR/smallfile" 55 56ORIG_PATTERN=$(mdb -ke "zfs_initialize_value/J" | tail -1 | awk '{print $NF}') 57log_must mdb -kwe "zfs_initialize_value/Z $PATTERN" 58 59log_must mkdir "$TESTDIR" 60log_must mkfile $MINVDEVSIZE "$SMALLFILE" 61log_must zpool create $TESTPOOL "$SMALLFILE" 62log_must zpool initialize $TESTPOOL 63 64while [[ "$(initialize_progress $TESTPOOL $SMALLFILE)" -lt "100" ]]; do 65 sleep 0.5 66done 67 68log_must zpool export $TESTPOOL 69 70spacemaps=0 71bs=512 72while read -r sm; do 73 typeset offset="$(echo $sm | cut -d ' ' -f1)" 74 typeset size="$(echo $sm | cut -d ' ' -f2)" 75 76 spacemaps=$((spacemaps + 1)) 77 offset=$(((4 * 1024 * 1024) + 16#$offset)) 78 out=$(dd if=$SMALLFILE skip=$(($offset / $bs)) \ 79 count=$(($size / $bs)) bs=$bs 2>/dev/null | od -t x8 -Ad) 80 echo "$out" | log_must egrep "$PATTERN|\*|$size" 81done <<< "$(zdb -p $TESTDIR -Pme $TESTPOOL | egrep 'spacemap[ ]+0 ' | \ 82 awk '{print $4, $8}')" 83 84if [[ $spacemaps -eq 0 ]];then 85 log_fail "Did not find any empty space maps to check" 86else 87 log_pass "Initializing wrote appropriate amount to disk" 88fi 89