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	"@(#)bootfs_006_pos.ksh	1.3	08/11/03 SMI"
30#
31
32. $STF_SUITE/include/libtest.kshlib
33
34################################################################################
35#
36# __stc_assertion_start
37#
38# ID:  bootfs_006_pos
39#
40# DESCRIPTION:
41#
42# Pools of correct vdev types accept boot property
43#
44# STRATEGY:
45# 1. create pools of each vdev type (raid, raidz, raidz2, mirror + hotspares)
46# 2. verify we can set bootfs on each pool type according to design
47#
48# TESTABILITY: explicit
49#
50# TEST_AUTOMATION_LEVEL: automated
51#
52# CODING_STATUS: COMPLETED (2007-03-05)
53#
54# __stc_assertion_end
55#
56################################################################################
57
58verify_runnable "global"
59
60$ZPOOL set 2>&1 | $GREP bootfs > /dev/null
61if [ $? -ne 0 ]
62then
63	log_unsupported "bootfs pool property not supported on this release."
64fi
65
66VDEV1=$TMPDIR/bootfs_006_pos_a.${TESTCASE_ID}.dat
67VDEV2=$TMPDIR/bootfs_006_pos_b.${TESTCASE_ID}.dat
68VDEV3=$TMPDIR/bootfs_006_pos_c.${TESTCASE_ID}.dat
69VDEV4=$TMPDIR/bootfs_006_pos_d.${TESTCASE_ID}.dat
70
71function verify_bootfs { # $POOL
72	POOL=$1
73	log_must $ZFS create $POOL/$FS
74
75	enc=$(get_prop encryption $POOL/$FS)
76	if [[ $? -eq 0 ]] && [[ -n "$enc" ]] && [[ "$enc" != "off" ]]; then
77		log_unsupported "bootfs pool property not supported \
78when encryption is set to on."
79	fi
80
81	log_must $ZPOOL set bootfs=$POOL/$FS $POOL
82	VAL=$($ZPOOL get bootfs $POOL | $TAIL -1 | $AWK '{print $3}' )
83	if [ $VAL != "$POOL/$FS" ]
84	then
85		log_must $ZPOOL status -v $POOL
86		log_fail "set/get failed on $POOL - expected $VAL == $POOL/$FS"
87	fi
88	log_must $ZPOOL destroy $POOL
89}
90
91function verify_no_bootfs { # $POOL
92	POOL=$1
93	log_must $ZFS create $POOL/$FS
94	log_mustnot $ZPOOL set bootfs=$POOL/$FS $POOL
95	VAL=$($ZPOOL get bootfs $POOL | $TAIL -1 | $AWK '{print $3}' )
96	if [ $VAL == "$POOL/$FS" ]
97	then
98		log_must $ZPOOL status -v $POOL
99		log_fail "set/get unexpectedly failed $VAL != $POOL/$FS"
100	fi
101	log_must $ZPOOL destroy $POOL
102}
103
104function cleanup {
105	destroy_pool $TESTPOOL
106	log_must $RM $VDEV1 $VDEV2 $VDEV3 $VDEV4
107}
108
109log_assert "Pools of correct vdev types accept boot property"
110
111
112
113log_onexit cleanup
114log_must create_vdevs $VDEV1 $VDEV2 $VDEV3 $VDEV4
115
116
117## the following configurations are supported bootable pools
118
119# normal
120log_must $ZPOOL create $TESTPOOL $VDEV1
121verify_bootfs $TESTPOOL
122
123# normal + hotspare
124log_must $ZPOOL create $TESTPOOL $VDEV1 spare $VDEV2
125verify_bootfs $TESTPOOL
126
127# mirror
128log_must $ZPOOL create $TESTPOOL mirror $VDEV1 $VDEV2
129verify_bootfs $TESTPOOL
130
131# mirror + hotspare
132log_must $ZPOOL create $TESTPOOL mirror $VDEV1 $VDEV2 spare $VDEV3
133verify_bootfs $TESTPOOL
134
135## the following configurations are not supported as bootable pools in Solaris,
136## but they are in FreeBSD
137
138# stripe
139log_must $ZPOOL create $TESTPOOL $VDEV1 $VDEV2
140verify_bootfs $TESTPOOL
141
142# stripe + hotspare
143log_must $ZPOOL create $TESTPOOL $VDEV1 $VDEV2 spare $VDEV3
144verify_bootfs $TESTPOOL
145
146# raidz
147log_must $ZPOOL create $TESTPOOL raidz $VDEV1 $VDEV2
148verify_bootfs $TESTPOOL
149
150# raidz + hotspare
151log_must $ZPOOL create $TESTPOOL raidz $VDEV1 $VDEV2 spare $VDEV3
152verify_bootfs $TESTPOOL
153
154# raidz2
155log_must $ZPOOL create $TESTPOOL raidz2 $VDEV1 $VDEV2 $VDEV3
156verify_bootfs $TESTPOOL
157
158# raidz2 + hotspare
159log_must $ZPOOL create $TESTPOOL raidz2 $VDEV1 $VDEV2 $VDEV3 spare $VDEV4
160verify_bootfs $TESTPOOL
161
162log_pass "Pools of correct vdev types accept boot property"
163