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