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