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 2009 Sun Microsystems, Inc. All rights reserved. 27# Use is subject to license terms. 28# 29# ident "@(#)snapshot_015_pos.ksh 1.5 09/01/12 SMI" 30# 31 32. $STF_SUITE/include/libtest.kshlib 33. $STF_SUITE/tests/cli_root/zfs_rollback/zfs_rollback_common.kshlib 34 35################################################################################# 36# 37# __stc_assertion_start 38# 39# ID: snapshot_015_pos 40# 41# DESCRIPTION: 42# Verify snapshot can be created or destroy via mkdir or rm 43# in $(get_snapdir_name). 44# 45# STRATEGY: 46# 1. Verify make directories only successfully in $(get_snapdir_name). 47# 2. Verify snapshot can be created and destroy via mkdir and remove 48# directories in $(get_snapdir_name). 49# 3. Verify rollback to previous snapshot can succeed. 50# 4. Verify remove directory in snapdir can destroy snapshot. 51# 52# TESTABILITY: explicit 53# 54# TEST_AUTOMATION_LEVEL: automated 55# 56# CODING_STATUS: COMPLETED (2006-10-17) 57# 58# __stc_assertion_end 59# 60################################################################################ 61 62verify_runnable "both" 63 64function cleanup 65{ 66 typeset -i i=0 67 while ((i < snap_cnt)); do 68 typeset snap=$fs@snap.$i 69 datasetexists $snap && log_must $ZFS destroy -f $snap 70 71 ((i += 1)) 72 done 73} 74 75$ZFS 2>&1 | $GREP "allow" > /dev/null 76(($? != 0)) && log_unsupported 77 78log_assert "Verify snapshot can be created via mkdir in $(get_snapdir_name)." 79log_onexit cleanup 80 81[[ $os_name == "FreeBSD" ]] && \ 82 log_uninitiated "Directory operations on the $(get_snapdir_name) directory are not yet supported in FreeBSD" 83 84fs=$TESTPOOL/$TESTFS 85# Verify all the other directories are readonly. 86mntpnt=$(get_prop mountpoint $fs) 87snapdir=$mntpnt/.zfs 88set -A ro_dirs "$snapdir" "$snapdir/snap" "$snapdir/snapshot" 89for dir in ${ro_dirs[@]}; do 90 if [[ -d $dir ]]; then 91 log_mustnot $RM -rf $dir 92 log_mustnot $TOUCH $dir/testfile 93 else 94 log_mustnot $MKDIR $dir 95 fi 96done 97 98# Verify snapshot can be created via mkdir in $(get_snapdir_name) 99typeset -i snap_cnt=5 100typeset -i cnt=0 101while ((cnt < snap_cnt)); do 102 testfile=$mntpnt/testfile.$cnt 103 log_must $MKFILE 1M $testfile 104 log_must $MKDIR $mntpnt/$(get_snapdir_name)/snap.$cnt 105 if ! datasetexists $fs@snap.$cnt ; then 106 log_fail "ERROR: $fs@snap.$cnt should exists." 107 fi 108 109 ((cnt += 1)) 110done 111 112# Verify rollback to previous snapshot succeed. 113((cnt = RANDOM % snap_cnt)) 114log_must $ZFS rollback -r $fs@snap.$cnt 115 116typeset -i i=0 117while ((i < snap_cnt)); do 118 testfile=$mntpnt/testfile.$i 119 if ((i <= cnt)); then 120 if [[ ! -f $testfile ]]; then 121 log_fail "ERROR: $testfile should exists." 122 fi 123 else 124 if [[ -f $testfile ]]; then 125 log_fail "ERROR: $testfile should not exists." 126 fi 127 fi 128 129 ((i += 1)) 130done 131 132# Verify remove directory in snapdir can destroy snapshot. 133log_must $RMDIR $mntpnt/$(get_snapdir_name)/snap.$cnt 134log_mustnot datasetexists $fs@snap.$cnt 135 136log_pass "Verify snapshot can be created via mkdir in $(get_snapdir_name) passed." 137