1f38cb554SJohn Wren Kennedy#!/usr/bin/ksh -p
2f38cb554SJohn Wren Kennedy#
3f38cb554SJohn Wren Kennedy# CDDL HEADER START
4f38cb554SJohn Wren Kennedy#
5f38cb554SJohn Wren Kennedy# The contents of this file are subject to the terms of the
6f38cb554SJohn Wren Kennedy# Common Development and Distribution License (the "License").
7f38cb554SJohn Wren Kennedy# You may not use this file except in compliance with the License.
8f38cb554SJohn Wren Kennedy#
9f38cb554SJohn Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10f38cb554SJohn Wren Kennedy# or http://www.opensolaris.org/os/licensing.
11f38cb554SJohn Wren Kennedy# See the License for the specific language governing permissions
12f38cb554SJohn Wren Kennedy# and limitations under the License.
13f38cb554SJohn Wren Kennedy#
14f38cb554SJohn Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each
15f38cb554SJohn Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16f38cb554SJohn Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the
17f38cb554SJohn Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying
18f38cb554SJohn Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner]
19f38cb554SJohn Wren Kennedy#
20f38cb554SJohn Wren Kennedy# CDDL HEADER END
21f38cb554SJohn Wren Kennedy#
22f38cb554SJohn Wren Kennedy
23f38cb554SJohn Wren Kennedy#
24f38cb554SJohn Wren Kennedy# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
25f38cb554SJohn Wren Kennedy# Use is subject to license terms.
26f38cb554SJohn Wren Kennedy#
27f38cb554SJohn Wren Kennedy
28f38cb554SJohn Wren Kennedy#
29*1d32ba66SJohn Wren Kennedy# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
30f38cb554SJohn Wren Kennedy#
31f38cb554SJohn Wren Kennedy
32f38cb554SJohn Wren Kennedy. $STF_SUITE/tests/functional/cli_user/misc/misc.cfg
33f38cb554SJohn Wren Kennedy. $STF_SUITE/include/libtest.shlib
34f38cb554SJohn Wren Kennedy
35f38cb554SJohn Wren Kennedy# This setup script is moderately complex, as it creates scenarios for all
36f38cb554SJohn Wren Kennedy# of the tests included in this directory. Usually we'd want each test case
37f38cb554SJohn Wren Kennedy# to setup/teardown it's own configuration, but this would be time consuming
38f38cb554SJohn Wren Kennedy# given the nature of these tests. However, as a side-effect, one test
39f38cb554SJohn Wren Kennedy# leaving the system in an unknown state could impact other test cases.
40f38cb554SJohn Wren Kennedy
41f38cb554SJohn Wren Kennedy
42f38cb554SJohn Wren KennedyDISK=${DISKS%% *}
43f38cb554SJohn Wren KennedyVOLSIZE=150m
44f38cb554SJohn Wren KennedyTESTVOL=testvol
45f38cb554SJohn Wren Kennedy
46f38cb554SJohn Wren Kennedy# Create a default setup that includes a volume
47f38cb554SJohn Wren Kennedydefault_setup_noexit "$DISK" "" "volume"
48f38cb554SJohn Wren Kennedy
49f38cb554SJohn Wren Kennedy#
50f38cb554SJohn Wren Kennedy# The rest of this setup script creates a ZFS filesystem configuration
51f38cb554SJohn Wren Kennedy# that is used to test the rest of the zfs subcommands in this directory.
52f38cb554SJohn Wren Kennedy#
53f38cb554SJohn Wren Kennedy
54f38cb554SJohn Wren Kennedy# create a snapshot and a clone to test clone promote
55*1d32ba66SJohn Wren Kennedylog_must zfs snapshot $TESTPOOL/$TESTFS@snap
56*1d32ba66SJohn Wren Kennedylog_must zfs clone $TESTPOOL/$TESTFS@snap $TESTPOOL/$TESTFS/clone
57f38cb554SJohn Wren Kennedy# create a file in the filesystem that isn't in the above snapshot
58*1d32ba66SJohn Wren Kennedytouch /$TESTDIR/file.txt
59f38cb554SJohn Wren Kennedy
60f38cb554SJohn Wren Kennedy
61f38cb554SJohn Wren Kennedy# create a non-default property and a child we can use to test inherit
62*1d32ba66SJohn Wren Kennedylog_must zfs create $TESTPOOL/$TESTFS/$TESTFS2
63*1d32ba66SJohn Wren Kennedylog_must zfs set snapdir=hidden $TESTPOOL/$TESTFS
64f38cb554SJohn Wren Kennedy
65f38cb554SJohn Wren Kennedy
66f38cb554SJohn Wren Kennedy# create an unmounted filesystem to test unmount
67*1d32ba66SJohn Wren Kennedylog_must zfs create $TESTPOOL/$TESTFS/$TESTFS2.unmounted
68*1d32ba66SJohn Wren Kennedylog_must zfs unmount $TESTPOOL/$TESTFS/$TESTFS2.unmounted
69f38cb554SJohn Wren Kennedy
70f38cb554SJohn Wren Kennedy
71f38cb554SJohn Wren Kennedy# send our snapshot to a known file in /tmp
72*1d32ba66SJohn Wren Kennedyzfs send $TESTPOOL/$TESTFS@snap > /tmp/zfstest_datastream.dat
73f38cb554SJohn Wren Kennedyif [ ! -s /tmp/zfstest_datastream.dat ]
74f38cb554SJohn Wren Kennedythen
75f38cb554SJohn Wren Kennedy	log_fail "ZFS send datafile was not created!"
76f38cb554SJohn Wren Kennedyfi
77*1d32ba66SJohn Wren Kennedylog_must chmod 644 /tmp/zfstest_datastream.dat
78f38cb554SJohn Wren Kennedy
79f38cb554SJohn Wren Kennedy
80f38cb554SJohn Wren Kennedy# create a filesystem that has particular properties to test set/get
81*1d32ba66SJohn Wren Kennedylog_must zfs create -o version=1 $TESTPOOL/$TESTFS/prop
82f38cb554SJohn Wren Kennedyset -A props $PROP_NAMES
83f38cb554SJohn Wren Kennedyset -A prop_vals $PROP_VALS
84f38cb554SJohn Wren Kennedytypeset -i i=0
85f38cb554SJohn Wren Kennedy
86f38cb554SJohn Wren Kennedywhile [[ $i -lt ${#props[*]} ]]
87f38cb554SJohn Wren Kennedydo
88f38cb554SJohn Wren Kennedy	prop_name=${props[$i]}
89f38cb554SJohn Wren Kennedy	prop_val=${prop_vals[$i]}
90*1d32ba66SJohn Wren Kennedy	log_must zfs set $prop_name=$prop_val $TESTPOOL/$TESTFS/prop
91f38cb554SJohn Wren Kennedy	i=$(( $i + 1 ))
92f38cb554SJohn Wren Kennedydone
93f38cb554SJohn Wren Kennedy
94f38cb554SJohn Wren Kennedy# create a filesystem we don't mind renaming
95*1d32ba66SJohn Wren Kennedylog_must zfs create $TESTPOOL/$TESTFS/renameme
96f38cb554SJohn Wren Kennedy
97f38cb554SJohn Wren Kennedy
98f38cb554SJohn Wren Kennedyif is_global_zone
99f38cb554SJohn Wren Kennedythen
100f38cb554SJohn Wren Kennedy	# create a filesystem we can share
101*1d32ba66SJohn Wren Kennedy	log_must zfs create $TESTPOOL/$TESTFS/unshared
102*1d32ba66SJohn Wren Kennedy	log_must zfs set sharenfs=off $TESTPOOL/$TESTFS/unshared
103f38cb554SJohn Wren Kennedy
104f38cb554SJohn Wren Kennedy	# create a filesystem that we can unshare
105*1d32ba66SJohn Wren Kennedy	log_must zfs create $TESTPOOL/$TESTFS/shared
106*1d32ba66SJohn Wren Kennedy	log_must zfs set sharenfs=on $TESTPOOL/$TESTFS/shared
107f38cb554SJohn Wren Kennedyfi
108f38cb554SJohn Wren Kennedy
109f38cb554SJohn Wren Kennedy
110*1d32ba66SJohn Wren Kennedylog_must zfs create -o version=1 $TESTPOOL/$TESTFS/version1
111*1d32ba66SJohn Wren Kennedylog_must zfs create -o version=1 $TESTPOOL/$TESTFS/allowed
112*1d32ba66SJohn Wren Kennedylog_must zfs allow everyone create $TESTPOOL/$TESTFS/allowed
113f38cb554SJohn Wren Kennedy
114f38cb554SJohn Wren Kennedyif is_global_zone
115f38cb554SJohn Wren Kennedythen
116f38cb554SJohn Wren Kennedy
117f38cb554SJohn Wren Kennedy	# Now create several virtual disks to test zpool with
118f38cb554SJohn Wren Kennedy
119*1d32ba66SJohn Wren Kennedy	mkfile $MINVDEVSIZE /$TESTDIR/disk1.dat
120*1d32ba66SJohn Wren Kennedy	mkfile $MINVDEVSIZE /$TESTDIR/disk2.dat
121*1d32ba66SJohn Wren Kennedy	mkfile $MINVDEVSIZE /$TESTDIR/disk3.dat
122*1d32ba66SJohn Wren Kennedy	mkfile $MINVDEVSIZE /$TESTDIR/disk-additional.dat
123*1d32ba66SJohn Wren Kennedy	mkfile $MINVDEVSIZE /$TESTDIR/disk-export.dat
124*1d32ba66SJohn Wren Kennedy	mkfile $MINVDEVSIZE /$TESTDIR/disk-offline.dat
125*1d32ba66SJohn Wren Kennedy	mkfile $MINVDEVSIZE /$TESTDIR/disk-spare1.dat
126*1d32ba66SJohn Wren Kennedy	mkfile $MINVDEVSIZE /$TESTDIR/disk-spare2.dat
127f38cb554SJohn Wren Kennedy
128f38cb554SJohn Wren Kennedy	# and create a pool we can perform attach remove replace,
129f38cb554SJohn Wren Kennedy	# etc. operations with
130*1d32ba66SJohn Wren Kennedy	log_must zpool create $TESTPOOL.virt mirror /$TESTDIR/disk1.dat \
131f38cb554SJohn Wren Kennedy	/$TESTDIR/disk2.dat /$TESTDIR/disk3.dat /$TESTDIR/disk-offline.dat \
132f38cb554SJohn Wren Kennedy	spare /$TESTDIR/disk-spare1.dat
133f38cb554SJohn Wren Kennedy
134f38cb554SJohn Wren Kennedy
135f38cb554SJohn Wren Kennedy	# Offline one of the disks to test online
136*1d32ba66SJohn Wren Kennedy	log_must zpool offline $TESTPOOL.virt /$TESTDIR/disk-offline.dat
137f38cb554SJohn Wren Kennedy
138f38cb554SJohn Wren Kennedy
139f38cb554SJohn Wren Kennedy	# create an exported pool to test import
140*1d32ba66SJohn Wren Kennedy	log_must zpool create $TESTPOOL.exported /$TESTDIR/disk-export.dat
141*1d32ba66SJohn Wren Kennedy	log_must zpool export $TESTPOOL.exported
142f38cb554SJohn Wren Kennedy
143f38cb554SJohn Wren Kennedy	set -A props $POOL_PROPS
144f38cb554SJohn Wren Kennedy	set -A prop_vals $POOL_VALS
145f38cb554SJohn Wren Kennedy	typeset -i i=0
146f38cb554SJohn Wren Kennedy
147f38cb554SJohn Wren Kennedy	while [[ $i -lt ${#props[*]} ]]
148f38cb554SJohn Wren Kennedy	do
149f38cb554SJohn Wren Kennedy		prop_name=${props[$i]}
150f38cb554SJohn Wren Kennedy		prop_val=${prop_vals[$i]}
151*1d32ba66SJohn Wren Kennedy		log_must zpool set $prop_name=$prop_val $TESTPOOL
152f38cb554SJohn Wren Kennedy		i=$(( $i + 1 ))
153f38cb554SJohn Wren Kennedy	done
154f38cb554SJohn Wren Kennedy
155f38cb554SJohn Wren Kennedy	# copy a v1 pool from cli_root
156*1d32ba66SJohn Wren Kennedy	cp $STF_SUITE/tests/functional/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1.dat.bz2 \
157f38cb554SJohn Wren Kennedy	    /$TESTDIR
158*1d32ba66SJohn Wren Kennedy	log_must bunzip2 /$TESTDIR/zfs-pool-v1.dat.bz2
159*1d32ba66SJohn Wren Kennedy	log_must zpool import -d /$TESTDIR v1-pool
160f38cb554SJohn Wren Kennedyfi
161f38cb554SJohn Wren Kennedylog_pass
162