]> git.proxmox.com Git - mirror_zfs-debian.git/blob - tests/zfs-tests/tests/functional/cli_root/zpool_expand/zpool_expand_002_pos.ksh
New upstream version 0.7.2
[mirror_zfs-debian.git] / tests / zfs-tests / tests / functional / cli_root / zpool_expand / zpool_expand_002_pos.ksh
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 # 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 LUN 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 online -e to online the vdevs
47 # 5) Check that the pool size was expanded
48 #
49
50 verify_runnable "global"
51
52 function 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 [ -e ${TEMPFILE}.$i ] && log_must rm ${TEMPFILE}.$i
60 done
61 }
62
63 log_onexit cleanup
64
65 log_assert "zpool can expand after zpool online -e zvol vdevs on LUN expansion"
66
67
68 for type in " " mirror raidz raidz2; do
69 for i in 1 2 3; do
70 log_must truncate -s $org_size ${TEMPFILE}.$i
71 done
72
73 log_must zpool create $TESTPOOL1 $type $TEMPFILE.1 \
74 $TEMPFILE.2 $TEMPFILE.3
75
76 typeset autoexp=$(get_pool_prop autoexpand $TESTPOOL1)
77
78 if [[ $autoexp != "off" ]]; then
79 log_fail "zpool $TESTPOOL1 autoexpand should off but is " \
80 "$autoexp"
81 fi
82 typeset prev_size=$(get_pool_prop size $TESTPOOL1)
83 typeset zfs_prev_size=$(zfs get -p avail $TESTPOOL1 | tail -1 | \
84 awk '{print $3}')
85
86 for i in 1 2 3; do
87 log_must truncate -s $exp_size ${TEMPFILE}.$i
88 done
89
90 for i in 1 2 3; do
91 log_must zpool online -e $TESTPOOL1 ${TEMPFILE}.$i
92 done
93
94 sync
95 sleep 10
96 sync
97
98 typeset expand_size=$(get_pool_prop size $TESTPOOL1)
99 typeset zfs_expand_size=$(zfs get -p avail $TESTPOOL1 | tail -1 | \
100 awk '{print $3}')
101 log_note "$TESTPOOL1 $type has previous size: $prev_size and " \
102 "expanded size: $expand_size"
103
104 # compare available pool size from zfs
105 if [[ $zfs_expand_size -gt $zfs_prev_size ]]; then
106 # check for zpool history for the pool size expansion
107 if [[ $type == " " ]]; then
108 typeset expansion_size=$(($exp_size-$org_size))
109 typeset size_addition=$(zpool history -il $TESTPOOL1 \
110 | grep "pool '$TESTPOOL1' size:" | \
111 grep "vdev online" | \
112 grep "(+${expansion_size}" | 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 typeset expansion_size=$(($exp_size-$org_size))
120 zpool history -il $TESTPOOL1 | \
121 grep "pool '$TESTPOOL1' size:" | \
122 grep "vdev online" | \
123 grep "(+${expansion_size})" >/dev/null 2>&1
124
125 if [[ $? -ne 0 ]]; then
126 log_fail "pool $TESTPOOL1 is not autoexpand " \
127 "after LUN expansion"
128 fi
129 else
130 typeset expansion_size=$((3*($exp_size-$org_size)))
131 zpool history -il $TESTPOOL1 | \
132 grep "pool '$TESTPOOL1' size:" | \
133 grep "vdev online" | \
134 grep "(+${expansion_size})" >/dev/null 2>&1
135
136 if [[ $? -ne 0 ]] ; then
137 log_fail "pool $TESTPOOL1 is not autoexpand " \
138 "after LUN expansion"
139 fi
140 fi
141 else
142 log_fail "pool $TESTPOOL1 is not autoexpanded after LUN " \
143 "expansion"
144 fi
145 log_must zpool destroy $TESTPOOL1
146 done
147 log_pass "zpool can expand after zpool online -e zvol vdevs on LUN expansion"