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) 2018 by Lawrence Livermore National Security, LLC.
31#
32
33
34. $STF_SUITE/include/libtest.shlib
35. $STF_SUITE/tests/functional/cli_root/zpool_expand/zpool_expand.cfg
36
37#
38# Description:
39# Once set zpool autoexpand=off, zpool can *NOT* autoexpand by
40# Dynamic VDEV Expansion
41#
42#
43# STRATEGY:
44# 1) Create three vdevs (loopback, scsi_debug, and file)
45# 2) Create pool by using the different devices and set autoexpand=off
46# 3) Expand each device as appropriate
47# 4) Check that the pool size is not expanded
48#
49# NOTE: Three different device types are used in this test to verify
50# expansion of non-partitioned block devices (loopback), partitioned
51# block devices (scsi_debug), and non-disk file vdevs.  ZFS volumes
52# are not used in order to avoid a possible lock inversion when
53# layering pools on zvols.
54#
55
56verify_runnable "global"
57
58function cleanup
59{
60	poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
61
62	if losetup -a | grep -q $DEV1; then
63		losetup -d $DEV1
64	fi
65
66	rm -f $FILE_LO $FILE_RAW
67
68	block_device_wait
69	unload_scsi_debug
70}
71
72log_onexit cleanup
73
74log_assert "zpool can not expand if set autoexpand=off after vdev expansion"
75
76for type in " " mirror raidz raidz2; do
77	log_note "Setting up loopback, scsi_debug, and file vdevs"
78	log_must truncate -s $org_size $FILE_LO
79	DEV1=$(losetup -f)
80	log_must losetup $DEV1 $FILE_LO
81
82	load_scsi_debug $org_size_mb 1 1 1 '512b'
83	block_device_wait
84	DEV2=$(get_debug_device)
85
86	log_must truncate -s $org_size $FILE_RAW
87	DEV3=$FILE_RAW
88
89	# The -f is required since we're mixing disk and file vdevs.
90	log_must zpool create -f $TESTPOOL1 $type $DEV1 $DEV2 $DEV3
91
92	typeset autoexp=$(get_pool_prop autoexpand $TESTPOOL1)
93	if [[ $autoexp != "off" ]]; then
94		log_fail "zpool $TESTPOOL1 autoexpand should be off but is " \
95		    "$autoexp"
96	fi
97
98	typeset prev_size=$(get_pool_prop size $TESTPOOL1)
99
100
101	# Expand each device as appropriate being careful to add an artificial
102	# delay to ensure we get a single history entry for each.  This makes
103	# is easier to verify each expansion for the striped pool case, since
104	# they will not be merged in to a single larger expansion.
105	log_note "Expanding loopback, scsi_debug, and file vdevs"
106	log_must truncate -s $exp_size $FILE_LO
107	log_must losetup -c $DEV1
108	sleep 3
109
110	echo "2" > /sys/bus/pseudo/drivers/scsi_debug/virtual_gb
111	echo "1" > /sys/class/block/$DEV2/device/rescan
112	block_device_wait
113	sleep 3
114
115	log_must truncate -s $exp_size $FILE_RAW
116
117	# This is far longer than we should need to wait, but let's be sure.
118	sleep 5
119
120	# check for zpool history for the pool size expansion
121	zpool history -il $TESTPOOL1 | grep "pool '$TESTPOOL1' size:" | \
122	    grep "vdev online" >/dev/null 2>&1
123
124	if [[ $? -eq 0 ]]; then
125		log_fail "pool $TESTPOOL1 is not autoexpand after vdev " \
126		    "expansion"
127	fi
128
129	typeset expand_size=$(get_pool_prop size $TESTPOOL1)
130
131	if [[ "$prev_size" != "$expand_size" ]]; then
132		log_fail "pool $TESTPOOL1 size changed after vdev expansion"
133	fi
134
135	cleanup
136done
137
138log_pass "zpool can not autoexpand if autoexpand=off after vdev expansion"
139