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