xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_expand/zpool_expand_002_pos.ksh (revision d583b39bfb4e2571d3e41097c5c357ffe353ad45)
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 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# After zpool online -e poolname zvol vdevs, 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
45# 4) Expand the vol size by zfs set volsize
46# 5  Use zpool online -e to online the zvol vdevs
47# 6) Check that the pool size was expaned
48#
49
50verify_runnable "global"
51
52function cleanup
53{
54        if poolexists $TESTPOOL1; then
55                log_must $ZPOOL destroy $TESTPOOL1
56        fi
57
58	for i in 1 2 3; do
59		if datasetexists $VFS/vol$i; then
60			log_must $ZFS destroy $VFS/vol$i
61		fi
62	done
63}
64
65log_onexit cleanup
66
67log_assert "zpool can expand after zpool online -e zvol vdevs on LUN expansion"
68
69for i in 1 2 3; do
70	log_must $ZFS create -V $org_size $VFS/vol$i
71done
72
73for type in " " mirror raidz raidz2; do
74	log_must $ZPOOL create $TESTPOOL1 $type /dev/zvol/dsk/$VFS/vol1 \
75	    /dev/zvol/dsk/$VFS/vol2 /dev/zvol/dsk/$VFS/vol3
76
77	typeset autoexp=$(get_pool_prop autoexpand $TESTPOOL1)
78
79	if [[ $autoexp != "off" ]]; then
80		log_fail "zpool $TESTPOOL1 autoexpand should off but is " \
81		    "$autoexp"
82	fi
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	for i in 1 2 3; do
92		log_must $ZPOOL online -e $TESTPOOL1 /dev/zvol/dsk/$VFS/vol$i
93	done
94
95	$SYNC
96	$SLEEP 10
97	$SYNC
98
99	typeset expand_size=$(get_pool_prop size $TESTPOOL1)
100	typeset zfs_expand_size=$($ZFS get -p avail $TESTPOOL1 | $TAIL -1 | \
101	    $AWK '{print $3}')
102	log_note "$TESTPOOL1 $type has previous size: $prev_size and " \
103	    "expanded size: $expand_size"
104
105	# compare available pool size from zfs
106	if [[ $zfs_expand_size > $zfs_prev_size ]]; then
107	# check for zpool history for the pool size expansion
108		if [[ $type == " " ]]; then
109			typeset	size_addition=$($ZPOOL history -il $TESTPOOL1 \
110			    | $GREP "pool '$TESTPOOL1' size:" | \
111			    $GREP "vdev online" | \
112			    $GREP "(+${EX_1GB}" | wc -l)
113
114			if [[ $size_addition -ne $i ]]; then
115				log_fail "pool $TESTPOOL1 is not autoexpand " \
116				    "after LUN expansion"
117			fi
118		elif [[ $type == "mirror" ]]; then
119			$ZPOOL history -il $TESTPOOL1 | \
120			    $GREP "pool '$TESTPOOL1' size:" | \
121			    $GREP "vdev online" | \
122			    $GREP "(+${EX_1GB})" >/dev/null 2>&1
123
124			if [[ $? -ne 0 ]]; then
125				log_fail "pool $TESTPOOL1 is not autoexpand " \
126				    "after LUN expansion"
127			fi
128		else
129			$ZPOOL history -il $TESTPOOL1 | \
130			    $GREP "pool '$TESTPOOL1' size:" | \
131			    $GREP "vdev online" | \
132			    $GREP "(+${EX_3GB})" >/dev/null 2>&1
133
134			if [[ $? -ne 0 ]] ; then
135				log_fail "pool $TESTPOOL1 is not autoexpand " \
136				    "after LUN expansion"
137			fi
138		fi
139	else
140		log_fail "pool $TESTPOOL1 is not autoexpanded after LUN " \
141		    "expansion"
142	fi
143	log_must $ZPOOL destroy $TESTPOOL1
144	for i in 1 2 3; do
145		log_must $ZFS set volsize=$org_size $VFS/vol$i
146	done
147done
148log_pass "zpool can expand after zpool online -e zvol vdevs on LUN expansion"
149