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