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, 2018 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/include/libtest.shlib
33. $STF_SUITE/include/blkdev.shlib
34. $STF_SUITE/tests/functional/cli_root/zpool_expand/zpool_expand.cfg
35
36#
37# DESCRIPTION:
38#
39# STRATEGY:
40# 1) Create a scsi_debug device and a pool based on it
41# 2) Expand the device and rescan the scsi bus
42# 3) Reopen the pool and check that it detects new available space
43# 4) Online the device and check that the pool has been expanded
44#
45
46verify_runnable "global"
47
48function cleanup
49{
50	poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
51	unload_scsi_debug
52}
53
54log_onexit cleanup
55
56log_assert "zpool based on scsi device can be expanded with zpool online -e"
57
58# run scsi_debug to create a device
59MINVDEVSIZE_MB=$((MINVDEVSIZE / 1048576))
60load_scsi_debug $MINVDEVSIZE_MB 1 1 1 '512b'
61block_device_wait
62SDISK=$(get_debug_device)
63log_must zpool create $TESTPOOL1 $SDISK
64
65typeset autoexp=$(get_pool_prop autoexpand $TESTPOOL1)
66if [[ $autoexp != "off" ]]; then
67	log_fail "zpool $TESTPOOL1 autoexpand should be off but is $autoexp"
68fi
69
70typeset prev_size=$(get_pool_prop size $TESTPOOL1)
71log_note "original pool size: $prev_size"
72
73# resize the scsi_debug device
74echo "5" > /sys/bus/pseudo/drivers/scsi_debug/virtual_gb
75# rescan the device to detect the new size
76echo "1" > /sys/class/block/$SDISK/device/rescan
77block_device_wait
78
79# reopen the pool so ZFS can see the new space
80log_must zpool reopen $TESTPOOL1
81
82typeset expandsize=$(get_pool_prop expandsize $TESTPOOL1)
83log_note "pool expandsize: $expandsize"
84if [[ "$zpool_expandsize" = "-" ]]; then
85	log_fail "pool $TESTPOOL1 did not detect any " \
86	    "expandsize after reopen"
87fi
88
89# online the device so the zpool will use the new space
90log_must zpool online -e $TESTPOOL1 $SDISK
91
92typeset new_size=$(get_pool_prop size $TESTPOOL1)
93log_note "new pool size: $new_size"
94if [[ $new_size -le $prev_size ]]; then
95	log_fail "pool $TESTPOOL1 did not expand " \
96	    "after vdev expansion and zpool online -e"
97fi
98
99log_pass "zpool based on scsi_debug can be expanded with reopen and online -e"
100