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. $STF_SUITE/include/libtest.shlib 34. $STF_SUITE/tests/functional/cli_root/zpool_expand/zpool_expand.cfg 35 36# 37# DESCRIPTION: 38# Once zpool set autoexpand=on poolname, zpool can autoexpand by 39# Dynamic VDEV Expansion 40# 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=on 45# 3) Expand each device as appropriate 46# 4) Check that the pool size was 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 be autoexpanded after set autoexpand=on on vdev expansion" 74 75for type in " " mirror raidz draid:1s; 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 -o autoexpand=on $TESTPOOL1 $type \ 90 $DEV1 $DEV2 $DEV3 91 92 typeset autoexp=$(get_pool_prop autoexpand $TESTPOOL1) 93 if [[ $autoexp != "on" ]]; then 94 log_fail "zpool $TESTPOOL1 autoexpand should be on but is " \ 95 "$autoexp" 96 fi 97 98 typeset prev_size=$(get_pool_prop size $TESTPOOL1) 99 typeset zfs_prev_size=$(get_prop avail $TESTPOOL1) 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 log_must zpool online -e $TESTPOOL1 $FILE_RAW 117 118 typeset expand_size=$(get_pool_prop size $TESTPOOL1) 119 typeset zfs_expand_size=$(get_prop avail $TESTPOOL1) 120 121 log_note "$TESTPOOL1 $type has previous size: $prev_size and " \ 122 "expanded size: $expand_size" 123 # compare available pool size from zfs 124 if [[ $zfs_expand_size -gt $zfs_prev_size ]]; then 125 # check for zpool history for the pool size expansion 126 if [[ $type == " " ]]; then 127 typeset expansion_size=$(($exp_size-$org_size)) 128 typeset size_addition=$(zpool history -il $TESTPOOL1 |\ 129 grep "pool '$TESTPOOL1' size:" | \ 130 grep "vdev online" | \ 131 grep -c "(+${expansion_size}") 132 133 if [[ $size_addition -ne 3 ]]; then 134 log_fail "pool $TESTPOOL1 has not expanded, " \ 135 "$size_addition/3 vdevs expanded" 136 fi 137 elif [[ $type == "mirror" ]]; then 138 typeset expansion_size=$(($exp_size-$org_size)) 139 zpool history -il $TESTPOOL1 | \ 140 grep "pool '$TESTPOOL1' size:" | \ 141 grep "vdev online" | \ 142 grep -q "(+${expansion_size})" || 143 log_fail "pool $TESTPOOL1 has not expanded" 144 elif [[ $type == "draid:1s" ]]; then 145 typeset expansion_size=$((2*($exp_size-$org_size))) 146 zpool history -il $TESTPOOL1 | \ 147 grep "pool '$TESTPOOL1' size:" | \ 148 grep "vdev online" | \ 149 grep -q "(+${expansion_size})" || 150 log_fail "pool $TESTPOOL has not expanded" 151 else 152 typeset expansion_size=$((3*($exp_size-$org_size))) 153 zpool history -il $TESTPOOL1 | \ 154 grep "pool '$TESTPOOL1' size:" | \ 155 grep "vdev online" | \ 156 grep -q "(+${expansion_size})" || 157 log_fail "pool $TESTPOOL has not expanded" 158 fi 159 else 160 log_fail "pool $TESTPOOL1 is not autoexpanded after vdev " \ 161 "expansion. Previous size: $zfs_prev_size and expanded " \ 162 "size: $zfs_expand_size" 163 fi 164 165 cleanup 166done 167 168log_pass "zpool can autoexpand if autoexpand=on after vdev expansion" 169