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 https://opensource.org/licenses/CDDL-1.0.
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 'cksum'.
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 && log_must zfs destroy $SNAPCTR
53
54	if [ -e $SNAPDIR1 ]; then
55		log_must rm -rf $SNAPDIR1
56	fi
57
58	if [ -e $TESTDIR ]; then
59		log_must rm -rf $TESTDIR/*
60	fi
61}
62
63log_assert "Verify that a snapshot of a dataset is identical to " \
64    "the original dataset."
65log_onexit cleanup
66
67log_note "Create a file in the zfs filesystem..."
68log_must file_write -o create -f $TESTDIR1/$TESTFILE -b $BLOCKSZ \
69    -c $NUM_WRITES -d $DATA
70
71log_note "Sum the file, save for later comparison..."
72read -r FILE_SUM _ < <(cksum $TESTDIR1/$TESTFILE)
73log_note "FILE_SUM = $FILE_SUM"
74
75log_note "Create a snapshot and mount it..."
76log_must zfs snapshot $SNAPCTR
77
78log_note "Append to the original file..."
79log_must file_write -o append -f $TESTDIR1/$TESTFILE -b $BLOCKSZ \
80    -c $NUM_WRITES -d $DATA
81
82read -r SNAP_FILE_SUM _ < <(cksum $SNAPDIR1/$TESTFILE)
83if [ $SNAP_FILE_SUM -ne $FILE_SUM ]; then
84	log_fail "Sums do not match, aborting!! ($SNAP_FILE_SUM != $FILE_SUM)"
85fi
86
87log_pass "Both Sums match. ($SNAP_FILE_SUM == $FILE_SUM)"
88