1#!/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 https://opensource.org/licenses/CDDL-1.0.
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) 2012, 2016 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/include/libtest.shlib
33
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
44verify_runnable "global"
45
46
47VDEV1=$TESTDIR/bootfs_006_pos_a.$$.dat
48VDEV2=$TESTDIR/bootfs_006_pos_b.$$.dat
49VDEV3=$TESTDIR/bootfs_006_pos_c.$$.dat
50VDEV4=$TESTDIR/bootfs_006_pos_d.$$.dat
51
52function verify_bootfs { # $POOL
53	POOL=$1
54	log_must zfs create $POOL/$TESTFS
55
56	log_must zpool set bootfs=$POOL/$TESTFS $POOL
57	VAL=$(zpool get bootfs $POOL | awk 'END {print $3}' )
58	if [ $VAL != "$POOL/$TESTFS" ]
59	then
60		log_must zpool status -v $POOL
61		log_fail \
62		    "set/get failed on $POOL - expected $VAL == $POOL/$TESTFS"
63	fi
64	log_must zpool destroy $POOL
65}
66
67function verify_no_bootfs { # $POOL
68	POOL=$1
69	log_must zfs create $POOL/$TESTFS
70	log_mustnot zpool set bootfs=$POOL/$TESTFS $POOL
71	VAL=$(zpool get bootfs $POOL | awk 'END {print $3}' )
72	if [ $VAL == "$POOL/$TESTFS" ]
73	then
74		log_must zpool status -v $POOL
75		log_fail "set/get unexpectedly failed $VAL != $POOL/$TESTFS"
76	fi
77	log_must zpool destroy $POOL
78}
79
80function cleanup {
81	if poolexists $TESTPOOL
82	then
83		log_must zpool destroy $TESTPOOL
84	fi
85	log_must rm $VDEV1 $VDEV2 $VDEV3 $VDEV4
86}
87
88log_assert "Pools of correct vdev types accept boot property"
89
90
91
92log_onexit cleanup
93log_must mkfile $MINVDEVSIZE $VDEV1 $VDEV2 $VDEV3 $VDEV4
94
95
96## the following configurations are supported bootable pools
97
98# normal
99log_must zpool create $TESTPOOL $VDEV1
100verify_bootfs $TESTPOOL
101
102# normal + hotspare
103log_must zpool create $TESTPOOL $VDEV1 spare $VDEV2
104verify_bootfs $TESTPOOL
105
106# mirror
107log_must zpool create $TESTPOOL mirror $VDEV1 $VDEV2
108verify_bootfs $TESTPOOL
109
110# mirror + hotspare
111log_must zpool create $TESTPOOL mirror $VDEV1 $VDEV2 spare $VDEV3
112verify_bootfs $TESTPOOL
113
114if is_linux || is_freebsd; then
115	# stripe
116	log_must zpool create $TESTPOOL $VDEV1 $VDEV2
117	verify_bootfs $TESTPOOL
118
119	# stripe + hotspare
120	log_must zpool create $TESTPOOL $VDEV1 $VDEV2 spare $VDEV3
121	verify_bootfs $TESTPOOL
122else
123	## the following configurations are not supported as bootable pools
124
125	# stripe
126	log_must zpool create $TESTPOOL $VDEV1 $VDEV2
127	verify_no_bootfs $TESTPOOL
128
129	# stripe + hotspare
130	log_must zpool create $TESTPOOL $VDEV1 $VDEV2 spare $VDEV3
131	verify_no_bootfs $TESTPOOL
132fi
133
134# raidz
135log_must zpool create $TESTPOOL raidz $VDEV1 $VDEV2
136verify_bootfs $TESTPOOL
137
138# raidz + hotspare
139log_must zpool create $TESTPOOL raidz $VDEV1 $VDEV2 spare $VDEV3
140verify_bootfs $TESTPOOL
141
142# raidz2
143log_must zpool create $TESTPOOL raidz2 $VDEV1 $VDEV2 $VDEV3
144verify_bootfs $TESTPOOL
145
146# raidz2 + hotspare
147log_must zpool create $TESTPOOL raidz2 $VDEV1 $VDEV2 $VDEV3 spare $VDEV4
148verify_bootfs $TESTPOOL
149
150log_pass "Pools of correct vdev types accept boot property"
151