1#! /usr/local/bin/ksh93 -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. $STF_SUITE/include/libtest.kshlib
27
28################################################################################
29#
30# __stc_assertion_start
31#
32# ID: snapshot_003_pos
33#
34# DESCRIPTION:
35# Verify that many snapshots can be made on a zfs file system.
36#
37# STRATEGY:
38# 1) Create a files in the zfs file system
39# 2) Create a snapshot of the dataset
40# 3) Remove all the files from the original file system
41# 4) Verify consistency of each snapshot directory
42#
43# TESTABILITY: explicit
44#
45# TEST_AUTOMATION_LEVEL: automated
46#
47# CODING_STATUS: COMPLETED (2005-07-04)
48#
49# __stc_assertion_end
50#
51################################################################################
52
53verify_runnable "both"
54
55function cleanup
56{
57	typeset -i i=1
58	while [ $i -lt $COUNT ]; do
59		snapexists $SNAPFS.$i
60		if [[ $? -eq 0 ]]; then
61			log_must $ZFS destroy $SNAPFS.$i
62		fi
63
64		if [[ -e $SNAPDIR.$i ]]; then
65			log_must $RM -rf $SNAPDIR.$i > /dev/null 2>&1
66		fi
67
68		(( i = i + 1 ))
69	done
70
71	if [[ -e $TESTDIR ]]; then
72		log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
73	fi
74}
75
76log_assert "Verify many snapshots of a file system can be taken."
77
78log_onexit cleanup
79
80[[ -n $TESTDIR ]] && \
81    log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
82
83typeset -i COUNT=10
84
85log_note "Create some files in the $TESTDIR directory..."
86populate_dir $TESTDIR/file $COUNT $NUM_WRITES $BLOCKSZ ITER $SNAPFS
87
88log_note "Remove all of the original files"
89[[ -n $TESTDIR ]] && \
90    log_must $RM -rf $TESTDIR/file* > /dev/null 2>&1
91
92i=1
93while [[ $i -lt $COUNT ]]; do
94	FILECOUNT=`$LS $SNAPDIR.$i/file* | wc -l`
95	typeset j=1
96	while [ $j -lt $FILECOUNT ]; do
97		log_must $FILE_CHECK $SNAPDIR.$i/file.$j $j
98		(( j = j + 1 ))
99	done
100	(( i = i + 1 ))
101done
102
103log_pass "All files are consistent"
104