]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create.shlib
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.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 file for storage pool vdev
57 # $1, file size
58 #
59 function create_blockfile
60 {
61         typeset size=$1
62         typeset file=$(mktemp)
63         truncate -s $size $file
64         echo $file
65 }
66
67 #
68 # Find the storage device in /etc/vfstab
69 #
70 function find_vfstab_dev
71 {
72         typeset vfstabdev
73         typeset vfstabdevs=""
74         typeset line
75
76         if is_illumos; then
77                 vfstab="/etc/vfstab"
78                 tmpfile="$TEST_BASE_DIR/vfstab.tmp"
79         else
80                 vfstab="/etc/fstab"
81                 tmpfile="$TEST_BASE_DIR/fstab.tmp"
82         fi
83
84         cat $vfstab | grep "^${DEV_DSKDIR}" >$tmpfile
85         while read -r line
86         do
87                 vfstabdev=`echo "$line" | awk '{print $1}'`
88                 vfstabdev=${vfstabdev%%:}
89                 vfstabdevs="$vfstabdev $vfstabdevs"
90         done <$tmpfile
91
92         rm -f $tmpfile
93         echo $vfstabdevs
94 }
95
96 #
97 # Save the system current dump device configuration
98 #
99 function save_dump_dev
100 {
101         typeset dumpdev=""
102
103         if is_illumos; then
104                 typeset fnd="Dump device"
105                 dumpdev=`dumpadm | grep "$fnd" | cut -f2 -d : | \
106                         awk '{print $1}'`
107         fi
108         echo $dumpdev
109 }