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# This setup script is moderately complex, as it creates scenarios for all 30# of the tests included in this directory. Usually we'd want each test case 31# to setup/teardown it's own configuration, but this would be time consuming 32# given the nature of these tests. However, as a side-effect, one test 33# leaving the system in an unknown state could impact other test cases. 34 35 36DISK=${DISKS%% *} 37VOLSIZE=150m 38TESTVOL=testvol 39 40# Create a default setup that includes a volume 41default_setup_noexit "$DISK" "" "volume" 42 43# 44# The rest of this setup script creates a ZFS filesystem configuration 45# that is used to test the rest of the zfs subcommands in this directory. 46# 47 48# create a snapshot and a clone to test clone promote 49log_must $ZFS snapshot $TESTPOOL/$TESTFS@snap 50log_must $ZFS clone $TESTPOOL/$TESTFS@snap $TESTPOOL/$TESTFS/clone 51# create a file in the filesystem that isn't in the above snapshot 52$TOUCH /$TESTDIR/file.txt 53 54 55# create a non-default property and a child we can use to test inherit 56log_must $ZFS create $TESTPOOL/$TESTFS/$TESTFS2 57log_must $ZFS set snapdir=hidden $TESTPOOL/$TESTFS 58 59 60# create an unmounted filesystem to test unmount 61log_must $ZFS create $TESTPOOL/$TESTFS/$TESTFS2.unmounted 62log_must $ZFS unmount $TESTPOOL/$TESTFS/$TESTFS2.unmounted 63 64 65# send our snapshot to a known file in $TMPDIR 66$ZFS send $TESTPOOL/$TESTFS@snap > $TMPDIR/zfstest_datastream.dat 67if [ ! -s $TMPDIR/zfstest_datastream.dat ] 68then 69 log_fail "Zfs send datafile was not created!" 70fi 71log_must $CHMOD 644 $TMPDIR/zfstest_datastream.dat 72 73 74# create a filesystem that has particular properties to test set/get 75log_must $ZFS create -o version=1 $TESTPOOL/$TESTFS/prop 76set -A props $PROP_NAMES 77set -A prop_vals $PROP_VALS 78typeset -i i=0 79 80while [[ $i -lt ${#props[*]} ]] 81do 82 prop_name=${props[$i]} 83 prop_val=${prop_vals[$i]} 84 log_must $ZFS set $prop_name=$prop_val $TESTPOOL/$TESTFS/prop 85 i=$(( $i + 1 )) 86done 87 88 89# create a filesystem we don't mind renaming 90log_must $ZFS create $TESTPOOL/$TESTFS/renameme 91 92 93if is_global_zone 94then 95 # create a filesystem we can share 96 log_must $ZFS create $TESTPOOL/$TESTFS/unshared 97 log_must $ZFS set sharenfs=off $TESTPOOL/$TESTFS/unshared 98 99 # create a filesystem that we can unshare 100 log_must $ZFS create $TESTPOOL/$TESTFS/shared 101 log_must $ZFS set sharenfs=on $TESTPOOL/$TESTFS/shared 102fi 103 104 105# check for upgrade support 106$ZFS upgrade > /dev/null 2>&1 107HAS_UPGRADE=$? 108 109if [ $HAS_UPGRADE -eq 0 ] 110then 111 log_must $ZFS create -o version=1 $TESTPOOL/$TESTFS/version1 112fi 113 114$ZFS 2>&1 | $GREP "allow" > /dev/null 115if (( $? == 0 )); then 116 log_must $ZFS create -o version=1 $TESTPOOL/$TESTFS/allowed 117 log_must $ZFS allow everyone create $TESTPOOL/$TESTFS/allowed 118fi 119 120if is_global_zone; then 121 # Now create several virtual disks to test zpool with 122 log_must create_vdevs \ 123 /$TESTDIR/disk1.dat \ 124 /$TESTDIR/disk2.dat \ 125 /$TESTDIR/disk3.dat \ 126 /$TESTDIR/disk-additional.dat \ 127 /$TESTDIR/disk-export.dat \ 128 /$TESTDIR/disk-offline.dat \ 129 /$TESTDIR/disk-spare1.dat \ 130 /$TESTDIR/disk-spare2.dat 131 132 # and create a pool we can perform attach remove replace, 133 # etc. operations with 134 log_must $ZPOOL create $TESTPOOL.virt mirror /$TESTDIR/disk1.dat \ 135 /$TESTDIR/disk2.dat /$TESTDIR/disk3.dat /$TESTDIR/disk-offline.dat \ 136 spare /$TESTDIR/disk-spare1.dat 137 138 # Offline one of the disks to test online 139 log_must $ZPOOL offline $TESTPOOL.virt /$TESTDIR/disk-offline.dat 140 141 # create an exported pool to test import 142 log_must $ZPOOL create $TESTPOOL.exported /$TESTDIR/disk-export.dat 143 log_must $ZPOOL export $TESTPOOL.exported 144 145 # Now setup pool properties if they're supported 146 GET=$($ZPOOL 2>&1 | $FGREP "get <all") 147 if [ -n "$GET" ] 148 then 149 set -A props $POOL_PROPS 150 set -A prop_vals $POOL_VALS 151 typeset -i i=0 152 153 while [[ $i -lt ${#props[*]} ]] 154 do 155 prop_name=${props[$i]} 156 prop_val=${prop_vals[$i]} 157 log_must $ZPOOL set $prop_name=$prop_val $TESTPOOL 158 i=$(( $i + 1 )) 159 done 160 fi 161 162 # copy a v1 pool from cli_root 163 $CP $STF_SUITE/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1.dat.Z \ 164 /$TESTDIR 165 log_must $UNCOMPRESS /$TESTDIR/zfs-pool-v1.dat.Z 166 log_must $ZPOOL import -d /$TESTDIR v1-pool 167fi 168log_pass 169