1#! /bin/ksh -p
2# SPDX-License-Identifier: CDDL-1.0
3#
4# CDDL HEADER START
5#
6# The contents of this file are subject to the terms of the
7# Common Development and Distribution License (the "License").
8# You may not use this file except in compliance with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or https://opensource.org/licenses/CDDL-1.0.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23
24#
25# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
26# Use is subject to license terms.
27#
28
29#
30# Copyright (c) 2012, 2018 by Delphix. All rights reserved.
31#
32
33. $STF_SUITE/include/libtest.shlib
34. $STF_SUITE/include/blkdev.shlib
35. $STF_SUITE/tests/functional/cli_root/zpool_expand/zpool_expand.cfg
36
37#
38# DESCRIPTION:
39#
40# STRATEGY:
41# 1) Create a scsi_debug device and a pool based on it
42# 2) Expand the device and rescan the scsi bus
43# 3) Reopen the pool and check that it detects new available space
44# 4) Online the device and check that the pool has been expanded
45#
46
47verify_runnable "global"
48
49function cleanup
50{
51	poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
52	unload_scsi_debug
53}
54
55log_onexit cleanup
56
57log_assert "zpool based on scsi device can be expanded with zpool online -e"
58
59# run scsi_debug to create a device
60MINVDEVSIZE_MB=$((MINVDEVSIZE / 1048576))
61load_scsi_debug $MINVDEVSIZE_MB 1 1 1 '512b'
62block_device_wait
63SDISK=$(get_debug_device)
64log_must zpool create $TESTPOOL1 $SDISK
65
66typeset autoexp=$(get_pool_prop autoexpand $TESTPOOL1)
67if [[ $autoexp != "off" ]]; then
68	log_fail "zpool $TESTPOOL1 autoexpand should be off but is $autoexp"
69fi
70
71typeset prev_size=$(get_pool_prop size $TESTPOOL1)
72log_note "original pool size: $prev_size"
73
74# resize the scsi_debug device
75echo "5" > /sys/bus/pseudo/drivers/scsi_debug/virtual_gb
76# rescan the device to detect the new size
77echo "1" > /sys/class/block/$SDISK/device/rescan
78block_device_wait
79
80# reopen the pool so ZFS can see the new space
81log_must zpool reopen $TESTPOOL1
82
83typeset expandsize=$(get_pool_prop expandsize $TESTPOOL1)
84log_note "pool expandsize: $expandsize"
85if [[ "$zpool_expandsize" = "-" ]]; then
86	log_fail "pool $TESTPOOL1 did not detect any " \
87	    "expandsize after reopen"
88fi
89
90# online the device so the zpool will use the new space
91log_must zpool online -e $TESTPOOL1 $SDISK
92
93typeset new_size=$(get_pool_prop size $TESTPOOL1)
94log_note "new pool size: $new_size"
95if [[ $new_size -le $prev_size ]]; then
96	log_fail "pool $TESTPOOL1 did not expand " \
97	    "after vdev expansion and zpool online -e"
98fi
99
100log_pass "zpool based on scsi_debug can be expanded with reopen and online -e"
101