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 2009 Sun Microsystems, Inc. All rights reserved. 25# Use is subject to license terms. 26# 27 28# 29# Copyright (c) 2012, 2018 by Delphix. All rights reserved. 30# Copyright (c) 2017 Lawrence Livermore National Security, LLC. 31# 32 33. $STF_SUITE/include/libtest.shlib 34. $STF_SUITE/tests/functional/cli_root/zpool_expand/zpool_expand.cfg 35 36# 37# DESCRIPTION: 38# After zpool online -e poolname zvol vdevs, zpool can autoexpand by 39# Dynamic VDEV Expansion 40# 41# 42# STRATEGY: 43# 1) Create 3 files 44# 2) Create a pool backed by the files 45# 3) Expand the files' size with truncate 46# 4) Use zpool reopen to check the expandsize 47# 5) Use zpool online -e to online the vdevs 48# 6) Check that the pool size was expanded 49# 50 51verify_runnable "global" 52 53function cleanup 54{ 55 poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1 56 57 for i in 1 2 3; do 58 [ -e ${TEMPFILE}.$i ] && log_must rm ${TEMPFILE}.$i 59 done 60} 61 62log_onexit cleanup 63 64log_assert "zpool can expand after zpool online -e zvol vdevs on vdev expansion" 65 66for type in " " mirror raidz draid:1s; do 67 # Initialize the file devices and the pool 68 for i in 1 2 3; do 69 log_must truncate -s $org_size ${TEMPFILE}.$i 70 done 71 72 log_must zpool create $TESTPOOL1 $type $TEMPFILE.1 \ 73 $TEMPFILE.2 $TEMPFILE.3 74 75 typeset autoexp=$(get_pool_prop autoexpand $TESTPOOL1) 76 77 if [[ $autoexp != "off" ]]; then 78 log_fail "zpool $TESTPOOL1 autoexpand should be off but is " \ 79 "$autoexp" 80 fi 81 typeset prev_size=$(get_pool_prop size $TESTPOOL1) 82 typeset zfs_prev_size=$(get_prop avail $TESTPOOL1) 83 84 # Increase the size of the file devices 85 for i in 1 2 3; do 86 log_must truncate -s $exp_size ${TEMPFILE}.$i 87 done 88 89 # Reopen the pool and check that the `expandsize` property is set 90 log_must zpool reopen $TESTPOOL1 91 typeset zpool_expandsize=$(get_pool_prop expandsize $TESTPOOL1) 92 93 if [[ $type == "mirror" ]]; then 94 typeset expected_zpool_expandsize=$(($exp_size-$org_size)) 95 elif [[ $type == "draid:1s" ]]; then 96 typeset expected_zpool_expandsize=$((2*($exp_size-$org_size))) 97 else 98 typeset expected_zpool_expandsize=$((3*($exp_size-$org_size))) 99 fi 100 101 if [[ "$zpool_expandsize" = "-" ]]; then 102 log_fail "pool $TESTPOOL1 did not detect any " \ 103 "expandsize after reopen" 104 fi 105 106 if [[ $zpool_expandsize -ne $expected_zpool_expandsize ]]; then 107 log_fail "pool $TESTPOOL1 did not detect correct " \ 108 "expandsize after reopen: found $zpool_expandsize," \ 109 "expected $expected_zpool_expandsize" 110 fi 111 112 # Online the devices to add the new space to the pool. Add an 113 # artificial delay between online commands order to prevent them 114 # from being merged in to a single history entry. This makes 115 # is easier to verify each expansion for the striped pool case. 116 for i in 1 2 3; do 117 log_must zpool online -e $TESTPOOL1 ${TEMPFILE}.$i 118 sleep 3 119 done 120 121 typeset expand_size=$(get_pool_prop size $TESTPOOL1) 122 typeset zfs_expand_size=$(get_prop avail $TESTPOOL1) 123 log_note "$TESTPOOL1 $type has previous size: $prev_size and " \ 124 "expanded size: $expand_size" 125 126 # compare available pool size from zfs 127 if [[ $zfs_expand_size -gt $zfs_prev_size ]]; then 128 # check for zpool history for the pool size expansion 129 if [[ $type == " " ]]; then 130 typeset expansion_size=$(($exp_size-$org_size)) 131 typeset size_addition=$(zpool history -il $TESTPOOL1 \ 132 | grep "pool '$TESTPOOL1' size:" | \ 133 grep "vdev online" | \ 134 grep -c "(+${expansion_size}") 135 136 if [[ $size_addition -ne $i ]]; then 137 log_fail "pool $TESTPOOL1 has not expanded " \ 138 "after zpool online -e, " \ 139 "$size_addition/3 vdevs expanded" 140 fi 141 elif [[ $type == "mirror" ]]; then 142 typeset expansion_size=$(($exp_size-$org_size)) 143 zpool history -il $TESTPOOL1 | \ 144 grep "pool '$TESTPOOL1' size:" | \ 145 grep "vdev online" | \ 146 grep -q "(+${expansion_size})" || 147 log_fail "pool $TESTPOOL1 has not expanded " \ 148 "after zpool online -e" 149 elif [[ $type == "draid:1s" ]]; then 150 typeset expansion_size=$((2*($exp_size-$org_size))) 151 zpool history -il $TESTPOOL1 | \ 152 grep "pool '$TESTPOOL1' size:" | \ 153 grep "vdev online" | \ 154 grep -q "(+${expansion_size})" || 155 log_fail "pool $TESTPOOL1 has not expanded " \ 156 "after zpool online -e" 157 else 158 typeset expansion_size=$((3*($exp_size-$org_size))) 159 zpool history -il $TESTPOOL1 | \ 160 grep "pool '$TESTPOOL1' size:" | \ 161 grep "vdev online" | \ 162 grep -q "(+${expansion_size})" || 163 log_fail "pool $TESTPOOL1 has not expanded " \ 164 "after zpool online -e" 165 fi 166 else 167 log_fail "pool $TESTPOOL1 did not expand after vdev " \ 168 "expansion and zpool online -e" 169 fi 170 171 # For dRAID pools verify the distributed spare was resized after 172 # expansion and it is large enough to be used to replace a pool vdev. 173 if [[ $type == "draid:1s" ]]; then 174 log_must zpool replace -w $TESTPOOL1 $TEMPFILE.3 draid1-0-0 175 verify_pool $TESTPOOL1 176 fi 177 178 log_must zpool destroy $TESTPOOL1 179done 180log_pass "zpool can expand after zpool online -e" 181