]> git.proxmox.com Git - mirror_zfs.git/blob - tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create.shlib
Update ZTS to work on FreeBSD
[mirror_zfs.git] / tests / zfs-tests / tests / functional / cli_root / zpool_create / zpool_create.shlib
1 #
2 # CDDL HEADER START
3 #
4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
7 #
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
12 #
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
18 #
19 # CDDL HEADER END
20 #
21
22 #
23 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
25 #
26
27 #
28 # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
29 #
30
31 . $STF_SUITE/include/libtest.shlib
32 . $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.cfg
33
34 #
35 # Given a pool vdevs list, create the pool,verify the created pool,
36 # and destroy the pool
37 # $1, pool name
38 # $2, pool type, mirror, raidz, or none
39 # $3, vdevs list
40 #
41 function create_pool_test
42 {
43 typeset pool=$1
44 typeset keywd=$2
45 typeset vdevs
46 eval "typeset -a diskarray=($3)"
47
48 for vdevs in "${diskarray[@]}"; do
49 create_pool $pool $keywd $vdevs
50 log_must poolexists $pool
51 destroy_pool $pool
52 done
53 }
54
55 #
56 # Create a ufs|ext file system and make a file within the file
57 # system for storage pool vdev
58 # $1, file size
59 # $2, file name
60 # $3, disk name to create ufs|ext file system
61 #
62 function create_blockfile
63 {
64 typeset size=$1
65 typeset file=$2
66 typeset disk=$3
67 typeset dir=`dirname $file`
68
69 if [[ -d $dir ]]; then
70 ismounted $dir $NEWFS_DEFAULT_FS
71 (( $? == 0 )) && \
72 log_must umount -f $dir
73 else
74 log_must mkdir -p $dir
75 fi
76
77 log_must eval "new_fs ${DEV_RDSKDIR}/$disk >/dev/null 2>&1"
78
79 log_must mount ${DEV_DSKDIR}/$disk $dir
80 log_must truncate -s $size $file
81 }
82
83 #
84 # Umount the ufs|ext filesystem and remove the mountpoint
85 # $1, the mount point
86 #
87 function clean_blockfile
88 {
89 typeset dirs=$1
90
91 for dir in $dirs; do
92 if [[ -d $dir ]]; then
93 if is_linux; then
94 if ismounted $dir ext2; then
95 typeset dev=$(df -lht ext2 | \
96 grep "$dir" | \
97 awk '{print $1}')
98 log_must umount -f $dir
99 create_pool ${TESTPOOL}.tmp $dev
100 destroy_pool ${TESTPOOL}.tmp
101 fi
102 else
103 if ismounted $dir ufs; then
104 typeset dev=$(df -lhF ufs | \
105 grep "$dir" | \
106 awk '{print $1}')
107 log_must umount -f $dir
108 create_pool ${TESTPOOL}.tmp $dev
109 destroy_pool ${TESTPOOL}.tmp
110 fi
111 fi
112 log_must rm -rf $dir
113 fi
114 done
115 }
116
117 #
118 # Find the storage device in /etc/vfstab
119 #
120 function find_vfstab_dev
121 {
122 typeset vfstabdev
123 typeset vfstabdevs=""
124 typeset line
125
126 if is_freebsd || is_linux; then
127 vfstab="/etc/fstab"
128 tmpfile="$TEST_BASE_DIR/fstab.tmp"
129 else
130 vfstab="/etc/vfstab"
131 tmpfile="$TEST_BASE_DIR/vfstab.tmp"
132 fi
133
134 cat $vfstab | grep "^${DEV_DSKDIR}" >$tmpfile
135 while read -r line
136 do
137 vfstabdev=`echo "$line" | awk '{print $1}'`
138 vfstabdev=${vfstabdev%%:}
139 vfstabdevs="$vfstabdev $vfstabdevs"
140 done <$tmpfile
141
142 rm -f $tmpfile
143 echo $vfstabdevs
144 }
145
146 #
147 # Save the system current dump device configuration
148 #
149 function save_dump_dev
150 {
151 typeset dumpdev
152
153 if is_freebsd; then
154 dumpdev=$(dumpon -l)
155 elif is_linux; then
156 dumpdev=""
157 else
158 typeset fnd="Dump device"
159 dumpdev=`dumpadm | grep "$fnd" | cut -f2 -d : | \
160 awk '{print $1}'`
161 fi
162 echo $dumpdev
163 }