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# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
33. $STF_SUITE/include/libtest.shlib
34
35# This setup script is moderately complex, as it creates scenarios for all
36# of the tests included in this directory. Usually we'd want each test case
37# to setup/teardown it's own configuration, but this would be time consuming
38# given the nature of these tests. However, as a side-effect, one test
39# leaving the system in an unknown state could impact other test cases.
40
41
42DISK=${DISKS%% *}
43VOLSIZE=150m
44TESTVOL=testvol
45
46# Create a default setup that includes a volume
47default_setup_noexit "$DISK" "" "volume"
48
49#
50# The rest of this setup script creates a ZFS filesystem configuration
51# that is used to test the rest of the zfs subcommands in this directory.
52#
53
54# create a snapshot and a clone to test clone promote
55log_must zfs snapshot $TESTPOOL/$TESTFS@snap
56log_must zfs clone $TESTPOOL/$TESTFS@snap $TESTPOOL/$TESTFS/clone
57# create a file in the filesystem that isn't in the above snapshot
58touch /$TESTDIR/file.txt
59
60
61# create a non-default property and a child we can use to test inherit
62log_must zfs create $TESTPOOL/$TESTFS/$TESTFS2
63log_must zfs set snapdir=hidden $TESTPOOL/$TESTFS
64
65
66# create an unmounted filesystem to test unmount
67log_must zfs create $TESTPOOL/$TESTFS/$TESTFS2.unmounted
68log_must zfs unmount $TESTPOOL/$TESTFS/$TESTFS2.unmounted
69
70
71# send our snapshot to a known file in /tmp
72zfs send $TESTPOOL/$TESTFS@snap > /tmp/zfstest_datastream.dat
73if [ ! -s /tmp/zfstest_datastream.dat ]
74then
75	log_fail "ZFS send datafile was not created!"
76fi
77log_must chmod 644 /tmp/zfstest_datastream.dat
78
79
80# create a filesystem that has particular properties to test set/get
81log_must zfs create -o version=1 $TESTPOOL/$TESTFS/prop
82set -A props $PROP_NAMES
83set -A prop_vals $PROP_VALS
84typeset -i i=0
85
86while [[ $i -lt ${#props[*]} ]]
87do
88	prop_name=${props[$i]}
89	prop_val=${prop_vals[$i]}
90	log_must zfs set $prop_name=$prop_val $TESTPOOL/$TESTFS/prop
91	i=$(( $i + 1 ))
92done
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
110log_must zfs create -o version=1 $TESTPOOL/$TESTFS/version1
111log_must zfs create -o version=1 $TESTPOOL/$TESTFS/allowed
112log_must zfs allow everyone create $TESTPOOL/$TESTFS/allowed
113
114if is_global_zone
115then
116
117	# Now create several virtual disks to test zpool with
118
119	mkfile $MINVDEVSIZE /$TESTDIR/disk1.dat
120	mkfile $MINVDEVSIZE /$TESTDIR/disk2.dat
121	mkfile $MINVDEVSIZE /$TESTDIR/disk3.dat
122	mkfile $MINVDEVSIZE /$TESTDIR/disk-additional.dat
123	mkfile $MINVDEVSIZE /$TESTDIR/disk-export.dat
124	mkfile $MINVDEVSIZE /$TESTDIR/disk-offline.dat
125	mkfile $MINVDEVSIZE /$TESTDIR/disk-spare1.dat
126	mkfile $MINVDEVSIZE /$TESTDIR/disk-spare2.dat
127
128	# and create a pool we can perform attach remove replace,
129	# etc. operations with
130	log_must zpool create $TESTPOOL.virt mirror /$TESTDIR/disk1.dat \
131	/$TESTDIR/disk2.dat /$TESTDIR/disk3.dat /$TESTDIR/disk-offline.dat \
132	spare /$TESTDIR/disk-spare1.dat
133
134
135	# Offline one of the disks to test online
136	log_must zpool offline $TESTPOOL.virt /$TESTDIR/disk-offline.dat
137
138
139	# create an exported pool to test import
140	log_must zpool create $TESTPOOL.exported /$TESTDIR/disk-export.dat
141	log_must zpool export $TESTPOOL.exported
142
143	set -A props $POOL_PROPS
144	set -A prop_vals $POOL_VALS
145	typeset -i i=0
146
147	while [[ $i -lt ${#props[*]} ]]
148	do
149		prop_name=${props[$i]}
150		prop_val=${prop_vals[$i]}
151		log_must zpool set $prop_name=$prop_val $TESTPOOL
152		i=$(( $i + 1 ))
153	done
154
155	# copy a v1 pool from cli_root
156	cp $STF_SUITE/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1.dat.bz2 \
157	    /$TESTDIR
158	log_must bunzip2 /$TESTDIR/zfs-pool-v1.dat.bz2
159	log_must zpool import -d /$TESTDIR v1-pool
160fi
161log_pass
162