xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_006_pos.ksh (revision f985abb4a2473d3c04b086f7c9fab177e368ffef)
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. $STF_SUITE/include/libtest.shlib
28. $STF_SUITE/tests/functional/cli_root/zpool_add/zpool_add.kshlib
29
30#
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.
34#
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.
42#
43
44verify_runnable "global"
45
46function cleanup
47{
48	poolexists $TESTPOOL1 && \
49		destroy_pool $TESTPOOL1
50
51	datasetexists $TESTPOOL/$TESTFS && \
52		log_must $ZFS destroy -f $TESTPOOL/$TESTFS
53	poolexists $TESTPOOL && \
54		destroy_pool $TESTPOOL
55
56	if [[ -d $TESTDIR ]]; then
57		log_must $RM -rf $TESTDIR
58	fi
59
60	partition_cleanup
61}
62
63
64#
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
68#
69
70function setup_vdevs #<disk>
71{
72	typeset disk=$1
73	typeset -l count=0
74	typeset -l largest_num=0
75	typeset -l slicesize=0
76	typeset vdev=""
77
78
79	#
80	# Get disk size for zfs filesystem
81	#
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
86
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
100		fi
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
105        fi
106
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
113
114	# Create a pool first using the first file, and make subsequent files
115	# ready as vdevs to add to the pool
116
117	log_must $MKFILE ${file_size}m ${TESTDIR}/file.$count
118	create_pool "$TESTPOOL1" "${TESTDIR}/file.$count"
119	log_must poolexists "$TESTPOOL1"
120
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
126}
127
128log_assert " 'zpool add [-f]' can add large numbers of vdevs to the specified" \
129	   " pool without any errors."
130log_onexit cleanup
131
132if [[ $DISK_ARRAY_NUM == 0 ]]; then
133        disk=$DISK
134else
135        disk=$DISK0
136fi
137
138vdevs_list=""
139vdevs_num=$VDEVS_NUM
140file_size=$FILE_SIZE
141
142setup_vdevs $disk
143log_must $ZPOOL add -f "$TESTPOOL1" $vdevs_list
144log_must iscontained "$TESTPOOL1" "$vdevs_list"
145
146(( file_size = file_size * (vdevs_num/40 + 1 ) ))
147log_mustnot $MKFILE ${file_size}m ${TESTDIR}/broken_file
148
149log_mustnot $ZPOOL add -f "$TESTPOOL1" ${TESTDIR}/broken_file
150log_mustnot iscontained "$TESTPOOL1" "${TESTDIR}/broken_file"
151
152log_pass "'zpool successfully add [-f]' can add large numbers of vdevs to the" \
153	 "specified pool without any errors."
154