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 2008 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)snapshot_017_pos.ksh	1.1	08/08/15 SMI"
30#
31
32. $STF_SUITE/include/libtest.kshlib
33
34################################################################################
35#
36# __stc_assertion_start
37#
38# ID: snapshot_017_pos
39#
40# DESCRIPTION:
41#
42# Directory structure of snapshots reflects filesystem structure.
43#
44# STRATEGY:
45#
46# This test makes sure that the directory structure of snapshots is
47# a proper reflection of the filesystem the snapshot was taken of.
48#
49# 1. Create a simple directory structure of files and directories
50# 2. Take a snapshot of the filesystem
51# 3. Modify original filesystem
52# 4. Walk down the snapshot directory structure verifying it
53#    checking with both absolute and relative paths
54#
55# TESTABILITY: explicit
56#
57# TEST_AUTOMATION_LEVEL: automated
58#
59# CODING_STATUS: COMPLETED (2007-05-31)
60#
61# __stc_assertion_end
62#
63################################################################################
64
65verify_runnable "both"
66
67function cleanup
68{
69	cd $SAVED_DIR
70
71	if datasetexists $TESTPOOL/$TESTFS ; then
72		log_must $ZFS destroy -Rf $TESTPOOL/$TESTFS
73	fi
74
75	log_must $ZFS create $TESTPOOL/$TESTFS
76	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
77}
78
79function verify_structure {
80
81	# check absolute paths
82	DIR=$PWD
83	verify_file $DIR/file1
84	verify_file $DIR/file2
85	verify_file $DIR/dir1/file3
86	verify_file $DIR/dir1/file4
87	verify_file $DIR/dir1/dir2/file5
88	verify_file $DIR/dir1/dir2/file6
89
90	verify_no_file $DIR/file99
91
92	# check relative paths
93	verify_file ./file1
94	verify_file ./file2
95	verify_file ./dir1/file3
96	verify_file ./dir1/file4
97	verify_file ./dir1/dir2/file5
98	verify_file ./dir1/dir2/file6
99
100	cd dir1
101	verify_file ../file1
102	verify_file ../file2
103	verify_file ./file3
104	verify_file ./file4
105
106	verify_no_file ../file99
107
108	cd dir2
109	verify_file ./file5
110	verify_file ./file6
111	verify_file ../file3
112	verify_file ../file4
113	verify_no_file ../file99
114
115	verify_file ../../file1
116	verify_file ../../file2
117	verify_no_file ../../file99
118}
119
120function verify_file {
121	if [ ! -e $1 ]
122	then
123		log_note "Working dir is $PWD"
124		log_fail "File $1 does not exist!"
125	fi
126}
127
128function verify_no_file {
129	if [ -e $1 ]
130	then
131		log_note "Working dir is $PWD"
132		log_fail "File $1 exists when it should not!"
133	fi
134}
135
136function verify_dir {
137	if [ ! -d $1 ]
138	then
139		log_note "Working dir is $PWD"
140		log_fail "Directory $1 does not exist!"
141	fi
142}
143
144log_assert "Directory structure of snapshots reflects filesystem structure."
145log_onexit cleanup
146
147SAVED_DIR=$PWD
148
149#
150# Create a directory structure with the following files
151#
152# ./file1
153# ./file2
154# ./dir1/file3
155# ./dir1/file4
156# ./dir1/dir2/file5
157# ./dir1/dir2/file6
158
159cd $TESTDIR
160$TOUCH file1
161$TOUCH file2
162$MKDIR dir1
163cd dir1
164$TOUCH file3
165$TOUCH file4
166$MKDIR dir2
167cd dir2
168$TOUCH file5
169$TOUCH file6
170
171# Now walk the directory structure verifying it
172cd $TESTDIR
173verify_structure
174
175# Take snapshots
176log_must $ZFS snapshot $TESTPOOL/$TESTFS@snap_a
177log_must $ZFS snapshot $TESTPOOL/$TESTFS@snap_b
178
179# Change the filesystem structure by renaming files in the original structure
180# The snapshot file structure should not change
181cd $TESTDIR
182log_must $MV file2 file99
183cd dir1
184log_must $MV file4 file99
185cd dir2
186log_must $MV file6 file99
187
188# verify the top level snapshot directories
189verify_dir $TESTDIR/$(get_snapdir_name)
190verify_dir $TESTDIR/$(get_snapdir_name)
191verify_dir $TESTDIR/$(get_snapdir_name)/snap_a
192verify_dir $TESTDIR/$(get_snapdir_name)/snap_b
193
194cd $TESTDIR/$(get_snapdir_name)/snap_a
195verify_structure
196
197cd $TESTDIR/$(get_snapdir_name)/snap_b
198verify_structure
199
200verify_dir $TESTDIR/$(get_snapdir_name)
201cd $TESTDIR/$(get_snapdir_name)
202verify_dir snap_a
203verify_dir snap_b
204
205cd snap_a
206verify_dir ../snap_a
207verify_dir ../snap_b
208
209cd ..
210verify_dir snap_a
211verify_dir snap_b
212
213log_pass "Directory structure of snapshots reflects filesystem structure."
214