1#! /bin/ksh -p
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#
27
28#
29# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/include/libtest.shlib
33. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
34
35#
36# DESCRIPTION:
37# to the originally snapshot'd file system, after the file
38# system has been changed. Uses 'sum -r'.
39#
40# STRATEGY:
41# 1) Create a file in the zfs dataset
42# 2) Sum the file for later comparison
43# 3) Create a snapshot of the dataset
44# 4) Append to the original file
45# 5) Verify both checksums match
46#
47
48verify_runnable "both"
49
50function cleanup
51{
52	snapexists $SNAPCTR
53	if [[ $? -eq 0 ]]; then
54		log_must zfs destroy $SNAPCTR
55	fi
56
57	if [[ -e $SNAPDIR1 ]]; then
58		log_must rm -rf $SNAPDIR1 > /dev/null 2>&1
59	fi
60
61	if [[ -e $TESTDIR ]]; then
62		log_must rm -rf $TESTDIR/* > /dev/null 2>&1
63	fi
64}
65
66log_assert "Verify that a snapshot of a dataset is identical to " \
67    "the original dataset."
68log_onexit cleanup
69
70log_note "Create a file in the zfs filesystem..."
71log_must file_write -o create -f $TESTDIR1/$TESTFILE -b $BLOCKSZ \
72    -c $NUM_WRITES -d $DATA
73
74log_note "Sum the file, save for later comparison..."
75FILE_SUM=`sum -r $TESTDIR1/$TESTFILE | awk  '{ print $1 }'`
76log_note "FILE_SUM = $FILE_SUM"
77
78log_note "Create a snapshot and mount it..."
79log_must zfs snapshot $SNAPCTR
80
81log_note "Append to the original file..."
82log_must file_write -o append -f $TESTDIR1/$TESTFILE -b $BLOCKSZ \
83    -c $NUM_WRITES -d $DATA
84
85SNAP_FILE_SUM=`sum -r $SNAPDIR1/$TESTFILE | awk '{ print $1 }'`
86if [[ $SNAP_FILE_SUM -ne $FILE_SUM ]]; then
87	log_fail "Sums do not match, aborting!! ($SNAP_FILE_SUM != $FILE_SUM)"
88fi
89
90log_pass "Both Sums match. ($SNAP_FILE_SUM == $FILE_SUM)"
91