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