1094e47e9SGeorge Wilson#!/bin/ksh -p 2094e47e9SGeorge Wilson# 3094e47e9SGeorge Wilson# CDDL HEADER START 4094e47e9SGeorge Wilson# 5094e47e9SGeorge Wilson# The contents of this file are subject to the terms of the 6094e47e9SGeorge Wilson# Common Development and Distribution License (the "License"). 7094e47e9SGeorge Wilson# You may not use this file except in compliance with the License. 8094e47e9SGeorge Wilson# 9094e47e9SGeorge Wilson# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10094e47e9SGeorge Wilson# or http://www.opensolaris.org/os/licensing. 11094e47e9SGeorge Wilson# See the License for the specific language governing permissions 12094e47e9SGeorge Wilson# and limitations under the License. 13094e47e9SGeorge Wilson# 14094e47e9SGeorge Wilson# When distributing Covered Code, include this CDDL HEADER in each 15094e47e9SGeorge Wilson# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16094e47e9SGeorge Wilson# If applicable, add the following below this CDDL HEADER, with the 17094e47e9SGeorge Wilson# fields enclosed by brackets "[]" replaced with your own identifying 18094e47e9SGeorge Wilson# information: Portions Copyright [yyyy] [name of copyright owner] 19094e47e9SGeorge Wilson# 20094e47e9SGeorge Wilson# CDDL HEADER END 21094e47e9SGeorge Wilson# 22094e47e9SGeorge Wilson 23094e47e9SGeorge Wilson# 24094e47e9SGeorge Wilson# Copyright (c) 2016 by Delphix. All rights reserved. 25094e47e9SGeorge Wilson# 26094e47e9SGeorge Wilson. $STF_SUITE/include/libtest.shlib 27094e47e9SGeorge Wilson. $STF_SUITE/tests/functional/cli_root/zpool_initialize/zpool_initialize.kshlib 28094e47e9SGeorge Wilson 29094e47e9SGeorge Wilson# 30094e47e9SGeorge Wilson# DESCRIPTION: 31094e47e9SGeorge Wilson# After initializing, the disk is actually initialized. 32094e47e9SGeorge Wilson# 33094e47e9SGeorge Wilson# STRATEGY: 34094e47e9SGeorge Wilson# 1. Create a one-disk pool. 35094e47e9SGeorge Wilson# 2. Initialize the disk to completion. 36*133d96a8SBrian Behlendorf# 3. Load all metaslabs and make sure that each contains at least 37*133d96a8SBrian Behlendorf# once instance of the initializing pattern (deadbeef). 38094e47e9SGeorge Wilson# 39094e47e9SGeorge Wilson 40094e47e9SGeorge Wilsonfunction cleanup 41094e47e9SGeorge Wilson{ 42094e47e9SGeorge Wilson mdb -kwe "zfs_initialize_value/Z $ORIG_PATTERN" 43094e47e9SGeorge Wilson zpool import -d $TESTDIR $TESTPOOL 44094e47e9SGeorge Wilson 45094e47e9SGeorge Wilson if datasetexists $TESTPOOL ; then 46094e47e9SGeorge Wilson zpool destroy -f $TESTPOOL 47094e47e9SGeorge Wilson fi 48094e47e9SGeorge Wilson if [[ -d "$TESTDIR" ]]; then 49094e47e9SGeorge Wilson rm -rf "$TESTDIR" 50094e47e9SGeorge Wilson fi 51094e47e9SGeorge Wilson} 52094e47e9SGeorge Wilsonlog_onexit cleanup 53*133d96a8SBrian Behlendorf 54094e47e9SGeorge WilsonPATTERN="deadbeefdeadbeef" 55094e47e9SGeorge WilsonSMALLFILE="$TESTDIR/smallfile" 56094e47e9SGeorge Wilson 57094e47e9SGeorge WilsonORIG_PATTERN=$(mdb -ke "zfs_initialize_value/J" | tail -1 | awk '{print $NF}') 58094e47e9SGeorge Wilsonlog_must mdb -kwe "zfs_initialize_value/Z $PATTERN" 59094e47e9SGeorge Wilson 60094e47e9SGeorge Wilsonlog_must mkdir "$TESTDIR" 61094e47e9SGeorge Wilsonlog_must mkfile $MINVDEVSIZE "$SMALLFILE" 62094e47e9SGeorge Wilsonlog_must zpool create $TESTPOOL "$SMALLFILE" 63094e47e9SGeorge Wilsonlog_must zpool initialize $TESTPOOL 64094e47e9SGeorge Wilson 65094e47e9SGeorge Wilsonwhile [[ "$(initialize_progress $TESTPOOL $SMALLFILE)" -lt "100" ]]; do 66094e47e9SGeorge Wilson sleep 0.5 67094e47e9SGeorge Wilsondone 68094e47e9SGeorge Wilson 69094e47e9SGeorge Wilsonlog_must zpool export $TESTPOOL 70094e47e9SGeorge Wilson 71*133d96a8SBrian Behlendorfmetaslabs=0 72094e47e9SGeorge Wilsonbs=512 73*133d96a8SBrian Behlendorfzdb -p $TESTDIR -Pme $TESTPOOL | awk '/metaslab[ ]+[0-9]+/ { print $4, $8 }' | 74*133d96a8SBrian Behlendorfwhile read -r offset size; do 75*133d96a8SBrian Behlendorf log_note "offset: '$offset'" 76*133d96a8SBrian Behlendorf log_note "size: '$size'" 77094e47e9SGeorge Wilson 78*133d96a8SBrian Behlendorf metaslabs=$((metaslabs + 1)) 79094e47e9SGeorge Wilson offset=$(((4 * 1024 * 1024) + 16#$offset)) 80*133d96a8SBrian Behlendorf log_note "vdev file offset: '$offset'" 81*133d96a8SBrian Behlendorf 82*133d96a8SBrian Behlendorf # Note we use '-t x4' instead of '-t x8' here because x8 is not 83*133d96a8SBrian Behlendorf # a supported format on FreeBSD. 84*133d96a8SBrian Behlendorf dd if=$SMALLFILE skip=$(($offset / $bs)) count=$(($size / $bs)) bs=$bs | 85*133d96a8SBrian Behlendorf od -t x4 -Ad | grep -qE "deadbeef +deadbeef +deadbeef +deadbeef" || 86*133d96a8SBrian Behlendorf log_fail "Pattern not found in metaslab free space" 87*133d96a8SBrian Behlendorfdone 88094e47e9SGeorge Wilson 89*133d96a8SBrian Behlendorfif [[ $metaslabs -eq 0 ]];then 90*133d96a8SBrian Behlendorf log_fail "Did not find any metaslabs to check" 91094e47e9SGeorge Wilsonelse 92*133d96a8SBrian Behlendorf log_pass "Initializing wrote to each metaslab" 93094e47e9SGeorge Wilsonfi 94