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