5847 libzfs_diff should check zfs_prop_get() return
[unleashed.git] / usr / src / test / zfs-tests / tests / functional / cli_root / zpool_add / zpool_add_006_pos.ksh
blobdf263112dbf5e4e50aa6405f0e053b75c4be8d74
1 #!/bin/ksh -p
3 # CDDL HEADER START
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.
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.
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]
20 # CDDL HEADER END
24 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
27 . $STF_SUITE/include/libtest.shlib
28 . $STF_SUITE/tests/functional/cli_root/zpool_add/zpool_add.kshlib
31 # DESCRIPTION:
32 # 'zpool add [-f]' can add large numbers of file-in-zfs-filesystem-based vdevs
33 # to the specified pool without any errors.
35 # STRATEGY:
36 # 1. Create assigned number of files in ZFS filesystem as vdevs and use the first
37 # file to create a pool
38 # 2. Add other vdevs to the pool should get success
39 # 3 Fill in the filesystem and create a partially written file
40 # as vdev
41 # 4. Add the new file into the pool should be failed.
44 verify_runnable "global"
46 function cleanup
48 poolexists $TESTPOOL1 && \
49 destroy_pool $TESTPOOL1
51 datasetexists $TESTPOOL/$TESTFS && \
52 log_must $ZFS destroy -f $TESTPOOL/$TESTFS
53 poolexists $TESTPOOL && \
54 destroy_pool $TESTPOOL
56 if [[ -d $TESTDIR ]]; then
57 log_must $RM -rf $TESTDIR
60 partition_cleanup
65 # Create a pool and fs on the assigned disk, and dynamically create large
66 # numbers of files as vdevs.(the default value is <VDEVS_NUM>)
67 # the first file will be used to create a pool for other vdevs to be added into
70 function setup_vdevs #<disk>
72 typeset disk=$1
73 typeset -l count=0
74 typeset -l largest_num=0
75 typeset -l slicesize=0
76 typeset vdev=""
80 # Get disk size for zfs filesystem
82 create_pool foo $disk
83 log_must $ZFS create foo/fs
84 typeset -l fs_size=$(get_prop "available" foo/fs)
85 destroy_pool foo
87 #64m is the minmum size for pool
88 (( largest_num = fs_size / (1024 * 1024 * 64) ))
89 if (( largest_num < $VDEVS_NUM )); then
90 # minus $largest_num/40 to leave 2.5% space for metadata.
91 (( vdevs_num=largest_num - largest_num/40 ))
92 file_size=64
93 vdev=$disk
94 else
95 vdevs_num=$VDEVS_NUM
96 file_size=$((fs_size / (1024 * 1024 * \
97 (vdevs_num + vdevs_num / 40))))
98 if (( file_size > FILE_SIZE )); then
99 file_size=$FILE_SIZE
101 # plus $vdevs_num/40 to provide enough space for metadata.
102 (( slice_size = file_size * (vdevs_num + vdevs_num/40) ))
103 set_partition 0 "" ${slice_size}m $disk
104 vdev=${disk}s0
107 create_pool $TESTPOOL $vdev
108 [[ -d $TESTDIR ]] && \
109 log_must $RM -rf $TESTDIR
110 log_must $MKDIR -p $TESTDIR
111 log_must $ZFS create $TESTPOOL/$TESTFS
112 log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
114 # Create a pool first using the first file, and make subsequent files
115 # ready as vdevs to add to the pool
117 log_must $MKFILE ${file_size}m ${TESTDIR}/file.$count
118 create_pool "$TESTPOOL1" "${TESTDIR}/file.$count"
119 log_must poolexists "$TESTPOOL1"
121 while (( count < vdevs_num )); do # minus 1 to avoid space non-enough
122 (( count = count + 1 ))
123 log_must $MKFILE ${file_size}m ${TESTDIR}/file.$count
124 vdevs_list="$vdevs_list ${TESTDIR}/file.$count"
125 done
128 log_assert " 'zpool add [-f]' can add large numbers of vdevs to the specified" \
129 " pool without any errors."
130 log_onexit cleanup
132 if [[ $DISK_ARRAY_NUM == 0 ]]; then
133 disk=$DISK
134 else
135 disk=$DISK0
138 vdevs_list=""
139 vdevs_num=$VDEVS_NUM
140 file_size=$FILE_SIZE
142 setup_vdevs $disk
143 log_must $ZPOOL add -f "$TESTPOOL1" $vdevs_list
144 log_must iscontained "$TESTPOOL1" "$vdevs_list"
146 (( file_size = file_size * (vdevs_num/40 + 1 ) ))
147 log_mustnot $MKFILE ${file_size}m ${TESTDIR}/broken_file
149 log_mustnot $ZPOOL add -f "$TESTPOOL1" ${TESTDIR}/broken_file
150 log_mustnot iscontained "$TESTPOOL1" "${TESTDIR}/broken_file"
152 log_pass "'zpool successfully add [-f]' can add large numbers of vdevs to the" \
153 "specified pool without any errors."