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) 2012, 2016 by Delphix. All rights reserved.
  30 # Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
  31 #
  32 
  33 . $STF_SUITE/include/libtest.shlib
  34 
  35 #
  36 # DESCRIPTION:
  37 #
  38 # Pools of correct vdev types accept boot property
  39 #
  40 # STRATEGY:
  41 # 1. create pools of each vdev type (raid, raidz, raidz2, mirror + hotspares)
  42 # 2. verify we can set bootfs on each pool type according to design
  43 #
  44 
  45 verify_runnable "global"
  46 
  47 
  48 zpool set 2>&1 | grep bootfs > /dev/null
  49 if [ $? -ne 0 ]
  50 then
  51         log_unsupported "bootfs pool property not supported on this release."
  52 fi
  53 
  54 VDEV1=/bootfs_006_pos_a.$$.dat
  55 VDEV2=/bootfs_006_pos_b.$$.dat
  56 VDEV3=/bootfs_006_pos_c.$$.dat
  57 VDEV4=/bootfs_006_pos_d.$$.dat
  58 
  59 function verify_bootfs { # $POOL
  60         POOL=$1
  61         log_must zfs create $POOL/$TESTFS
  62 
  63         log_must zpool set bootfs=$POOL/$TESTFS $POOL
  64         VAL=$(zpool get bootfs $POOL | tail -1 | awk '{print $3}' )
  65         if [ $VAL != "$POOL/$TESTFS" ]
  66         then
  67                 log_must zpool status -v $POOL
  68                 log_fail \
  69                     "set/get failed on $POOL - expected $VAL == $POOL/$TESTFS"
  70         fi
  71         log_must destroy_pool_no_force $POOL
  72 }
  73 
  74 function verify_no_bootfs { # $POOL
  75         POOL=$1
  76         log_must zfs create $POOL/$TESTFS
  77         log_mustnot zpool set bootfs=$POOL/$TESTFS $POOL
  78         VAL=$(zpool get bootfs $POOL | tail -1 | awk '{print $3}' )
  79         if [ $VAL == "$POOL/$TESTFS" ]
  80         then
  81                 log_must zpool status -v $POOL
  82                 log_fail "set/get unexpectedly failed $VAL != $POOL/$TESTFS"
  83         fi
  84         log_must destroy_pool_no_force $POOL
  85 }
  86 
  87 function cleanup {
  88         if poolexists $TESTPOOL
  89         then
  90                 log_must destroy_pool_no_force $TESTPOOL
  91         fi
  92         log_must rm $VDEV1 $VDEV2 $VDEV3 $VDEV4
  93 }
  94 
  95 log_assert "Pools of correct vdev types accept boot property"
  96 
  97 
  98 
  99 log_onexit cleanup
 100 log_must mkfile $MINVDEVSIZE $VDEV1 $VDEV2 $VDEV3 $VDEV4
 101 
 102 
 103 ## the following configurations are supported bootable pools
 104 
 105 # normal
 106 log_must zpool create $TESTPOOL $VDEV1
 107 verify_bootfs $TESTPOOL
 108 
 109 # normal + hotspare
 110 log_must zpool create $TESTPOOL $VDEV1 spare $VDEV2
 111 verify_bootfs $TESTPOOL
 112 
 113 # mirror
 114 log_must zpool create $TESTPOOL mirror $VDEV1 $VDEV2
 115 verify_bootfs $TESTPOOL
 116 
 117 # mirror + hotspare
 118 log_must zpool create $TESTPOOL mirror $VDEV1 $VDEV2 spare $VDEV3
 119 verify_bootfs $TESTPOOL
 120 
 121 ## the following configurations are not supported as bootable pools
 122 
 123 # stripe
 124 log_must zpool create $TESTPOOL $VDEV1 $VDEV2
 125 verify_no_bootfs $TESTPOOL
 126 
 127 # stripe + hotspare
 128 log_must zpool create $TESTPOOL $VDEV1 $VDEV2 spare $VDEV3
 129 verify_no_bootfs $TESTPOOL
 130 
 131 # raidz
 132 log_must zpool create $TESTPOOL raidz $VDEV1 $VDEV2
 133 verify_bootfs $TESTPOOL
 134 
 135 # raidz + hotspare
 136 log_must zpool create $TESTPOOL raidz $VDEV1 $VDEV2 spare $VDEV3
 137 verify_bootfs $TESTPOOL
 138 
 139 # raidz2
 140 log_must zpool create $TESTPOOL raidz2 $VDEV1 $VDEV2 $VDEV3
 141 verify_bootfs $TESTPOOL
 142 
 143 # raidz2 + hotspare
 144 log_must zpool create $TESTPOOL raidz2 $VDEV1 $VDEV2 $VDEV3 spare $VDEV4
 145 verify_bootfs $TESTPOOL
 146 
 147 log_pass "Pools of correct vdev types accept boot property"