xref: /titanic_51/usr/src/test/zfs-tests/tests/functional/snapshot/snapshot_007_pos.ksh (revision f38cb554a534c6df738be3f4d23327e69888e634)
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 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 dataset.
38#
39# STRATEGY:
40# 1) Create a file in the zfs dataset
41# 2) Create a snapshot of the dataset
42# 3) Remove all the files from the original dataset
43# 4) For each snapshot directory verify consistency
44#
45
46verify_runnable "both"
47
48function cleanup
49{
50	typeset -i i=1
51	while [ $i -lt $COUNT ]; do
52		snapexists $SNAPCTR.$i
53		if [[ $? -eq 0 ]]; then
54			log_must $ZFS destroy $SNAPCTR.$i
55		fi
56
57		if [[ -e $SNAPDIR.$i ]]; then
58			log_must $RM -rf $SNAPDIR1.$i > /dev/null 2>&1
59		fi
60
61		(( i = i + 1 ))
62	done
63
64	if [[ -e $SNAPDIR1 ]]; then
65		log_must $RM -rf $SNAPDIR1 > /dev/null 2>&1
66	fi
67
68	if [[ -e $TESTDIR ]]; then
69		log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
70	fi
71}
72
73log_assert "Verify that many snapshots can be made on a zfs dataset."
74
75log_onexit cleanup
76
77[[ -n $TESTDIR ]] && \
78    log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
79
80typeset -i COUNT=10
81
82log_note "Create some files in the $TESTDIR directory..."
83typeset -i i=1
84while [[ $i -lt $COUNT ]]; do
85	log_must $FILE_WRITE -o create -f $TESTDIR1/file$i \
86	   -b $BLOCKSZ -c $NUM_WRITES -d $i
87	log_must $ZFS snapshot $SNAPCTR.$i
88
89	(( i = i + 1 ))
90done
91
92log_note "Remove all of the original files"
93[[ -n $TESTDIR ]] && \
94    log_must $RM -rf $TESTDIR1/file* > /dev/null 2>&1
95
96i=1
97while [[ $i -lt $COUNT ]]; do
98	FILECOUNT=`$LS $SNAPDIR1.$i/file* | wc -l`
99	typeset j=1
100	while [ $j -lt $FILECOUNT ]; do
101		log_must $FILE_CHECK $SNAPDIR1.$i/file$j $j
102		(( j = j + 1 ))
103	done
104	(( i = i + 1 ))
105done
106
107log_pass "All files are consistent"
108