1#!/usr/local/bin/ksh93 -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. $STF_SUITE/include/libtest.kshlib 27. $STF_SUITE/tests/cli_root/zpool_add/zpool_add.kshlib 28 29################################################################################ 30# 31# __stc_assertion_start 32# 33# ID: zpool_add_006_pos 34# 35# DESCRIPTION: 36# 'zpool add [-f]' can add large numbers of file-in-zfs-filesystem-based vdevs 37# to the specified pool without any errors. 38# 39# STRATEGY: 40# 1. Create assigned number of files in ZFS filesystem as vdevs and use the first 41# file to create a pool 42# 2. Add other vdevs to the pool should get success 43# 3 Fill in the filesystem and create a partially written file 44# as vdev 45# 4. Add the new file into the pool should be failed. 46# 47# TESTABILITY: explicit 48# 49# TEST_AUTOMATION_LEVEL: automated 50# 51# CODING_STATUS: COMPLETED (2005-10-09) 52# 53# __stc_assertion_end 54# 55################################################################################ 56 57verify_runnable "global" 58 59function cleanup 60{ 61 poolexists $TESTPOOL1 && \ 62 destroy_pool $TESTPOOL1 63 64 poolexists $TESTPOOL && \ 65 destroy_pool $TESTPOOL 66 67 if [[ -d $TESTDIR ]]; then 68 log_must $RM -rf $TESTDIR 69 fi 70} 71 72 73# 74# Create a pool and fs on the assigned disk, and dynamically create large 75# numbers of files as vdevs.(the default value is <VDEVS_NUM>) 76# the first file will be used to create a pool for other vdevs to be added into 77# 78 79function setup_vdevs #<disk> 80{ 81 typeset disk=$1 82 typeset -i count=0 83 typeset -i largest_num=0 84 typeset -i slicesize=0 85 typeset vdev="" 86 87 fs_size=$(get_available_disk_size $disk) 88 89 # 64M is the minimum size for the pool 90 (( largest_num = fs_size / (1024 * 1024 * 64) )) 91 if (( largest_num < $VDEVS_NUM )); then 92 # Minus $largest_num/20 to leave 5% space for metadata. 93 (( vdevs_num=largest_num - largest_num/20 )) 94 file_size=64 95 else 96 vdevs_num=$VDEVS_NUM 97 (( file_size = fs_size / (1024 * 1024 * (vdevs_num + vdevs_num/20)) )) 98 if (( file_size > FILE_SIZE )); then 99 file_size=$FILE_SIZE 100 fi 101 # Plus $vdevs_num/20 to provide enough space for metadata. 102 (( slice_size = file_size * (vdevs_num + vdevs_num/20) )) 103 wipe_partition_table $disk 104 set_partition 0 "" ${slice_size}m $disk 105 fi 106 vdev=${disk} 107 108 create_pool $TESTPOOL $vdev 109 [[ -d $TESTDIR ]] && \ 110 log_must $RM -rf $TESTDIR 111 log_must $MKDIR -p $TESTDIR 112 log_must $ZFS create $TESTPOOL/$TESTFS 113 log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS 114 115# Create a pool first using the first file, and make subsequent files ready 116# as vdevs to add to the pool 117 118 vdev=${TESTDIR}/file.$count 119 VDEV_SIZE=${file_size}m 120 log_must create_vdevs ${TESTDIR}/file.$count 121 create_pool "$TESTPOOL1" "${TESTDIR}/file.$count" 122 log_must poolexists "$TESTPOOL1" 123 124 while (( count < vdevs_num )); do # minus 1 to avoid space non-enough 125 (( count = count + 1 )) 126 log_must create_vdevs ${TESTDIR}/file.$count 127 vdevs_list="$vdevs_list ${TESTDIR}/file.$count" 128 done 129 unset VDEV_SIZE 130} 131 132log_assert " 'zpool add [-f]' can add large numbers of vdevs to the specified" \ 133 " pool without any errors." 134log_onexit cleanup 135 136vdevs_list="" 137vdevs_num=$VDEVS_NUM 138file_size=$FILE_SIZE 139 140setup_vdevs $DISK0 141log_must $ZPOOL add -f "$TESTPOOL1" $vdevs_list 142log_must iscontained "$TESTPOOL1" "$vdevs_list" 143 144log_pass "'zpool successfully add [-f]' can add large numbers of vdevs to the" \ 145 "specified pool without any errors." 146