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 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 2009 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. $STF_SUITE/tests/functional/cli_root/zpool_expand/zpool_expand.cfg
34
35#
36# DESCRIPTION:
37# Once zpool set autoexpand=on poolname, zpool can autoexpand by
38# Dynamic LUN Expansion
39#
40#
41# STRATEGY:
42# 1) Create a pool
43# 2) Create volume on top of the pool
44# 3) Create pool by using the zvols and set autoexpand=on
45# 4) Expand the vol size by 'zfs set volsize'
46# 5) Check that the pool size was expanded
47#
48
49verify_runnable "global"
50
51function cleanup
52{
53	if poolexists $TESTPOOL1; then
54		log_must zpool destroy $TESTPOOL1
55	fi
56
57	for i in 1 2 3; do
58		if datasetexists $VFS/vol$i; then
59			log_must zfs destroy $VFS/vol$i
60		fi
61	done
62}
63
64log_onexit cleanup
65
66log_assert "zpool can be autoexpanded after set autoexpand=on on LUN expansion"
67
68for i in 1 2 3; do
69	log_must zfs create -V $org_size $VFS/vol$i
70done
71
72for type in " " mirror raidz raidz2; do
73
74	log_must zpool create -o autoexpand=on $TESTPOOL1 $type \
75	    /dev/zvol/dsk/$VFS/vol1  /dev/zvol/dsk/$VFS/vol2 \
76	    /dev/zvol/dsk/$VFS/vol3
77
78	typeset autoexp=$(get_pool_prop autoexpand $TESTPOOL1)
79	if [[ $autoexp != "on" ]]; then
80		log_fail "zpool $TESTPOOL1 autoexpand should on but is $autoexp"
81	fi
82
83	typeset prev_size=$(get_pool_prop size $TESTPOOL1)
84	typeset zfs_prev_size=$(zfs get -p avail $TESTPOOL1 | tail -1 | \
85	    awk '{print $3}')
86
87	for i in 1 2 3; do
88		log_must zfs set volsize=$exp_size $VFS/vol$i
89	done
90
91	sync
92	sleep 10
93	sync
94
95	typeset expand_size=$(get_pool_prop size $TESTPOOL1)
96	typeset zfs_expand_size=$(zfs get -p avail $TESTPOOL1 | tail -1 | \
97	    awk '{print $3}')
98
99	log_note "$TESTPOOL1 $type has previous size: $prev_size and " \
100	    "expanded size: $expand_size"
101	# compare available pool size from zfs
102	if (( zfs_expand_size > zfs_prev_size )); then
103	# check for zpool history for the pool size expansion
104		if [[ $type == " " ]]; then
105			typeset	size_addition=$(zpool history -il $TESTPOOL1 |\
106			    grep "pool '$TESTPOOL1' size:" | \
107			    grep "vdev online" | \
108			    grep "(+${EX_1GB}" | wc -l)
109
110			if (( size_addition != i )); then
111				log_fail "pool $TESTPOOL1 is not autoexpand " \
112				    "after LUN expansion"
113			fi
114		elif [[ $type == "mirror" ]]; then
115			zpool history -il $TESTPOOL1 | \
116			    grep "pool '$TESTPOOL1' size:" | \
117			    grep "vdev online" | \
118			    grep "(+${EX_1GB})" >/dev/null 2>&1
119
120			if (( $? != 0 )) ; then
121				log_fail "pool $TESTPOOL1 is not autoexpand " \
122				    "after LUN expansion"
123			fi
124		else
125			zpool history -il $TESTPOOL1 | \
126			    grep "pool '$TESTPOOL1' size:" | \
127			    grep "vdev online" | \
128			    grep "(+${EX_3GB})" >/dev/null 2>&1
129
130			if (( $? != 0 )); then
131				log_fail "pool $TESTPOOL is not autoexpand " \
132				    "after LUN expansion"
133			fi
134		fi
135	else
136		log_fail "pool $TESTPOOL1 is not autoexpanded after LUN " \
137		    "expansion"
138	fi
139
140	log_must zpool destroy $TESTPOOL1
141	for i in 1 2 3; do
142		log_must zfs set volsize=$org_size $VFS/vol$i
143	done
144
145done
146log_pass "zpool can be autoexpanded after set autoexpand=on on LUN expansion"
147