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# Verify that many snapshots can be made on a zfs file system.
38#
39# STRATEGY:
40# 1) Create a files in the zfs file system
41# 2) Create a snapshot of the dataset
42# 3) Remove all the files from the original file system
43# 4) Verify consistency of each snapshot directory
44#
45
46verify_runnable "both"
47
48function cleanup
49{
50	typeset -i i=1
51	while [ $i -lt $COUNT ]; do
52		snapexists $SNAPFS.$i && log_must zfs destroy $SNAPFS.$i
53
54		if [ -e $SNAPDIR.$i ]; then
55			log_must rm -rf $SNAPDIR.$i
56		fi
57
58		(( i = i + 1 ))
59	done
60
61	if [ -e $TESTDIR ]; then
62		log_must rm -rf $TESTDIR/*
63	fi
64}
65
66log_assert "Verify many snapshots of a file system can be taken."
67
68log_onexit cleanup
69
70[ -n $TESTDIR ] && log_must rm -rf $TESTDIR/*
71
72typeset -i COUNT=10
73
74log_note "Create some files in the $TESTDIR directory..."
75typeset -i i=1
76while [[ $i -lt $COUNT ]]; do
77	log_must file_write -o create -f $TESTDIR/file$i \
78	   -b $BLOCKSZ -c $NUM_WRITES -d $i
79	log_must zfs snapshot $SNAPFS.$i
80
81	(( i = i + 1 ))
82done
83
84log_note "Remove all of the original files"
85[ -n $TESTDIR ] && log_must rm -rf $TESTDIR/file*
86
87i=1
88while [[ $i -lt $COUNT ]]; do
89	FILECOUNT=$(ls $SNAPDIR.$i/file* | wc -l)
90	typeset j=1
91	while [ $j -lt $FILECOUNT ]; do
92		log_must file_check $SNAPDIR.$i/file$j $j
93		(( j = j + 1 ))
94	done
95	(( i = i + 1 ))
96done
97
98log_pass "All files are consistent"
99