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 and make sure that each contains at least 37# once instance of 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 53 54PATTERN="deadbeefdeadbeef" 55SMALLFILE="$TESTDIR/smallfile" 56 57ORIG_PATTERN=$(mdb -ke "zfs_initialize_value/J" | tail -1 | awk '{print $NF}') 58log_must mdb -kwe "zfs_initialize_value/Z $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 71metaslabs=0 72bs=512 73zdb -p $TESTDIR -Pme $TESTPOOL | awk '/metaslab[ ]+[0-9]+/ { print $4, $8 }' | 74while read -r offset size; do 75 log_note "offset: '$offset'" 76 log_note "size: '$size'" 77 78 metaslabs=$((metaslabs + 1)) 79 offset=$(((4 * 1024 * 1024) + 16#$offset)) 80 log_note "vdev file offset: '$offset'" 81 82 # Note we use '-t x4' instead of '-t x8' here because x8 is not 83 # a supported format on FreeBSD. 84 dd if=$SMALLFILE skip=$(($offset / $bs)) count=$(($size / $bs)) bs=$bs | 85 od -t x4 -Ad | grep -qE "deadbeef +deadbeef +deadbeef +deadbeef" || 86 log_fail "Pattern not found in metaslab free space" 87done 88 89if [[ $metaslabs -eq 0 ]];then 90 log_fail "Did not find any metaslabs to check" 91else 92 log_pass "Initializing wrote to each metaslab" 93fi 94