f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# CDDL HEADER START
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# The contents of this file are subject to the terms of the
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Common Development and Distribution License (the "License").
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# You may not use this file except in compliance with the License.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# or http://www.opensolaris.org/os/licensing.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# See the License for the specific language governing permissions
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# and limitations under the License.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner]
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# CDDL HEADER END
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Use is subject to license terms.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy. $STF_SUITE/tests/functional/clean_mirror/default.cfg
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Most of the code related to the clearing of mirrors is duplicated in all
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# the test cases below this directory, barring a few minor changes
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# involving the device to be affected and the 'object' to use to mangle
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# the contents of the mirror.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# This code is sourced into each of these test cases.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson#
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson# Synchronize all the data in pool
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson#
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson# $1 pool name
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson#
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilsonfunction sync_pool #pool
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson{
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson typeset pool=$1
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must sync
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must sleep 2
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson # Flush all the pool data.
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson typeset -i ret
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy zpool scrub $pool >/dev/null 2>&1
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson ret=$?
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson (( $ret != 0 )) && \
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_fail "zpool scrub $pool failed."
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson while ! is_pool_scrubbed $pool; do
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson if is_pool_resilvered $pool ; then
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson log_fail "$pool should not be resilver completed."
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson fi
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must sleep 2
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson done
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson}
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfunction overwrite_verify_mirror
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy{
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset AFFECTED_DEVICE=$1
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset OVERWRITING_DEVICE=$2
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset atfile=0
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy set -A files
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy set -A cksums
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy set -A newcksums
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy while (( atfile < FILE_COUNT )); do
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy files[$atfile]=$TESTDIR/file.$atfile
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must file_write -o create -f $TESTDIR/file.$atfile \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy -b $FILE_SIZE -c 1
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy cksums[$atfile]=$(cksum ${files[$atfile]})
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy (( atfile = atfile + 1 ))
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy done
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy # dd the primary side of the mirror
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must dd if=$OVERWRITING_DEVICE of=/dev/dsk/$AFFECTED_DEVICE \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy seek=8 bs=$DD_BLOCK count=$(( DD_COUNT - 8 )) conv=notrunc
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy atfile=0
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson #
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson # Flush out the cache so that we ensure we're reading from disk.
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson #
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must zpool export $TESTPOOL
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must zpool import $TESTPOOL
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy typeset -i failedcount=0
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy while (( atfile < FILE_COUNT )); do
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy files[$atfile]=$TESTDIR/file.$atfile
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy newcksum=$(cksum ${files[$atfile]})
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy if [[ $newcksum != ${cksums[$atfile]} ]]; then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy (( failedcount = failedcount + 1 ))
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy fi
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy rm -f ${files[$atfile]}
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy (( atfile = atfile + 1 ))
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy done
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy if (( $failedcount > 0 )); then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy log_fail "of the $FILE_COUNT files $failedcount did not " \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy "have the same checksum before and after."
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy fi
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson sync_pool $TESTPOOL
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy}