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 https://opensource.org/licenses/CDDL-1.0.
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#
31
32. $STF_SUITE/include/libtest.shlib
33. $STF_SUITE/tests/functional/clean_mirror/default.cfg
34
35function overwrite_verify_mirror
36{
37	typeset AFFECTED_DEVICE=$1
38	typeset OVERWRITING_DEVICE=$2
39
40	typeset atfile=0
41	set -A files
42	set -A cksums
43	set -A newcksums
44
45	while (( atfile < FILE_COUNT )); do
46		files[$atfile]=$TESTDIR/file.$atfile
47		log_must file_write -o create -f $TESTDIR/file.$atfile \
48			-b $FILE_SIZE -c 1
49		cksums[$atfile]=$(cksum ${files[$atfile]})
50		(( atfile = atfile + 1 ))
51	done
52
53	# dd the affected side of the mirror
54	log_must dd if=$OVERWRITING_DEVICE of=$AFFECTED_DEVICE \
55		seek=8 bs=$DD_BLOCK count=$(( DD_COUNT - 128 )) conv=notrunc
56
57	atfile=0
58
59	#
60	# Flush out the cache so that we ensure we're reading from disk.
61	#
62	log_must zpool export $TESTPOOL
63	log_must zpool import -d $SIDE_DIR $TESTPOOL
64
65	typeset -i failedcount=0
66	while (( atfile < FILE_COUNT )); do
67		files[$atfile]=$TESTDIR/file.$atfile
68		newcksum=$(cksum ${files[$atfile]})
69		if [[ $newcksum != ${cksums[$atfile]} ]]; then
70			(( failedcount = failedcount + 1 ))
71		fi
72		rm -f ${files[$atfile]}
73		(( atfile = atfile + 1 ))
74	done
75
76	if (( $failedcount > 0 )); then
77		log_fail "of the $FILE_COUNT files $failedcount did not " \
78		    "have the same checksum before and after."
79	fi
80
81	log_must zpool scrub $TESTPOOL
82	log_must wait_scrubbed $TESTPOOL
83}
84