1# vim: filetype=sh
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 2007 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26
27function overwrite_verify_mirror
28{
29	typeset POOL=$1
30	typeset AFFECTED_DEVICE=$2
31	typeset OVERWRITING_DEVICE=$3
32
33	typeset atfile=0
34	set -A files
35	set -A cksums
36	set -A newcksums
37
38	fill_fs $TESTDIR -1 $FILE_COUNT $BLOCKSZ $WRITE_COUNT
39	while [ "$atfile" -lt "$FILE_COUNT" ]; do
40		if [ -f ${TESTDIR}/0/${TESTFILE}.${atfile} ]; then
41			cksums[$atfile]=$($CKSUM ${TESTDIR}/0/${TESTFILE}.${atfile})
42		fi
43		(( atfile = $atfile + 1 ))
44	done
45
46	# unmount and export before dd
47	log_must $ZPOOL export $POOL
48
49	# dd the affected side of the mirror
50	log_must $DD if=$OVERWRITING_DEVICE of=$(bsddevmap $AFFECTED_DEVICE) \
51		seek=8 bs=$BLOCKSZ count=$(( WRITE_COUNT - 8 )) conv=notrunc
52
53	# now remount and scrub
54	log_must $ZPOOL import $POOL
55	log_must $ZPOOL scrub $POOL
56	wait_for 60 1 is_pool_scrubbed $POOL
57
58	atfile=0
59	typeset -i failedcount=0
60	while [ "$atfile" -lt "$FILE_COUNT" ]; do
61		if [ -f ${TESTDIR}/0/${TESTFILE}.${atfile} ]; then
62			newcksum=$($CKSUM $TESTDIR/0/${TESTFILE}.${atfile})
63			if [[ $newcksum != ${cksums[$atfile]} ]]; then
64				(( failedcount = $failedcount + 1 ))
65			else
66				log_note "${TESTFILE}.${atfile} checksums match:"\
67				    "old ${cksums[$atfile]} new $newcksum"
68			fi
69			$RM -f ${files[$atfile]}
70		fi
71		(( atfile = $atfile + 1 ))
72	done
73
74	if [ "$failedcount" -gt 0 ]; then
75		log_fail "of the $FILE_COUNT files $failedcount did not " \
76		    "have the same checksum before and after."
77	fi
78}
79