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