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, 2016 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 53verify_runnable "both" 54 55function 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 67function 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 108function 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 116function 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 124function 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 132log_assert "Directory structure of snapshots reflects filesystem structure." 133log_onexit cleanup 134 135SAVED_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 147cd $TESTDIR 148mkfile 10m file1 149mkfile 20m file2 150mkdir dir1 151cd dir1 152mkfile 10m file3 153mkfile 20m file4 154mkdir dir2 155cd dir2 156mkfile 10m file5 157mkfile 20m file6 158 159# Now walk the directory structure verifying it 160cd $TESTDIR 161verify_structure 162 163# Take snapshots 164log_must zfs snapshot $TESTPOOL/$TESTFS@snap_a 165log_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 169cd $TESTDIR 170log_must mv file2 file99 171cd dir1 172log_must mv file4 file99 173cd dir2 174log_must mv file6 file99 175 176# verify the top level snapshot directories 177verify_dir $TESTDIR/.zfs 178verify_dir $TESTDIR/.zfs/snapshot 179verify_dir $TESTDIR/.zfs/snapshot/snap_a 180verify_dir $TESTDIR/.zfs/snapshot/snap_b 181 182cd $TESTDIR/.zfs/snapshot/snap_a 183verify_structure 184 185cd $TESTDIR/.zfs/snapshot/snap_b 186verify_structure 187 188cd $TESTDIR/.zfs 189verify_dir snapshot 190cd $TESTDIR/.zfs/snapshot 191verify_dir snap_a 192verify_dir snap_b 193 194cd snap_a 195verify_dir ../snap_a 196verify_dir ../snap_b 197 198cd .. 199verify_dir snap_a 200verify_dir snap_b 201 202log_pass "Directory structure of snapshots reflects filesystem structure." 203