1# 2# CDDL HEADER START 3# 4# The contents of this file are subject to the terms of the 5# Common Development and Distribution License (the "License"). 6# You may not use this file except in compliance with the License. 7# 8# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9# or http://www.opensolaris.org/os/licensing. 10# See the License for the specific language governing permissions 11# and limitations under the License. 12# 13# When distributing Covered Code, include this CDDL HEADER in each 14# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15# If applicable, add the following below this CDDL HEADER, with the 16# fields enclosed by brackets "[]" replaced with your own identifying 17# information: Portions Copyright [yyyy] [name of copyright owner] 18# 19# CDDL HEADER END 20# 21 22# 23# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 24# Use is subject to license terms. 25# 26 27# 28# Copyright (c) 2013, 2016 by Delphix. All rights reserved. 29# Copyright (c) 2017 Datto Inc. 30# Copyright 2019 Joyent, Inc. 31# 32 33. $STF_SUITE/include/libtest.shlib 34. $STF_SUITE/tests/functional/clean_mirror/default.cfg 35 36# Most of the code related to the clearing of mirrors is duplicated in all 37# the test cases below this directory, barring a few minor changes 38# involving the device to be affected and the 'object' to use to mangle 39# the contents of the mirror. 40# This code is sourced into each of these test cases. 41 42function overwrite_verify_mirror 43{ 44 typeset AFFECTED_DEVICE=$1 45 typeset OVERWRITING_DEVICE=$2 46 47 typeset atfile=0 48 set -A files 49 set -A cksums 50 set -A newcksums 51 52 scrub_pool # Make sure we have a clean pool before starting the test. 53 54 while (( atfile < FILE_COUNT )); do 55 files[$atfile]=$TESTDIR/file.$atfile 56 log_must file_write -o create -f $TESTDIR/file.$atfile \ 57 -b $FILE_SIZE -c 1 58 cksums[$atfile]=$(cksum ${files[$atfile]}) 59 (( atfile = atfile + 1 )) 60 done 61 62 # dd the primary side of the mirror 63 log_must dd if=$OVERWRITING_DEVICE of=/dev/dsk/$AFFECTED_DEVICE \ 64 seek=8 bs=$DD_BLOCK count=$(( DD_COUNT - 8 )) conv=notrunc 65 66 atfile=0 67 68 # 69 # Flush out the cache so that we ensure we're reading from disk. 70 # 71 log_must zpool export $TESTPOOL 72 log_must zpool import $TESTPOOL 73 74 typeset -i failedcount=0 75 while (( atfile < FILE_COUNT )); do 76 files[$atfile]=$TESTDIR/file.$atfile 77 newcksum=$(cksum ${files[$atfile]}) 78 if [[ $newcksum != ${cksums[$atfile]} ]]; then 79 (( failedcount = failedcount + 1 )) 80 fi 81 rm -f ${files[$atfile]} 82 (( atfile = atfile + 1 )) 83 done 84 85 if (( $failedcount > 0 )); then 86 log_fail "of the $FILE_COUNT files $failedcount did not " \ 87 "have the same checksum before and after." 88 fi 89 90 sync_pool $TESTPOOL 91} 92 93# Scrub the pool and wait for completion. 94function scrub_pool 95{ 96 typeset pool=$TESTPOOL 97 log_note "Scrubbing $TESTPOOL" 98 99 # Flush all the pool data. 100 log_must zpool scrub $pool 101 102 while ! is_pool_scrubbed $pool; do 103 if is_pool_resilvered $pool ; then 104 log_fail "$pool should not have been resilvered" 105 fi 106 log_must sleep 2 107 done 108} 109