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