]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - zfs/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_all_001_pos.ksh
UBUNTU: SAUCE: Update zfs to e02aaf17f15ad274fa1f24c9c826f1477911ea3f
[mirror_ubuntu-zesty-kernel.git] / zfs / tests / zfs-tests / tests / functional / cli_root / zpool_import / zpool_import_all_001_pos.ksh
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 2008 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 #
29 # Copyright (c) 2012 by Delphix. All rights reserved.
30 #
31
32 . $STF_SUITE/include/libtest.shlib
33 . $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
34 . $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg
35
36 #
37 # DESCRIPTION:
38 # Verify that 'zpool import -a' succeeds as root.
39 #
40 # STRATEGY:
41 # 1. Create a group of pools with specified vdev.
42 # 2. Create zfs filesystems within the given pools.
43 # 3. Export the pools.
44 # 4. Verify that import command succeed.
45 #
46
47 verify_runnable "global"
48
49 set -A options "" "-R $ALTER_ROOT"
50
51 typeset -i number=0
52 typeset -i id=0
53 typeset -i i=0
54 typeset checksum1
55 typeset unwantedpool
56
57 function setup_single_disk #disk #pool #fs #mtpt
58 {
59 typeset disk=$1
60 typeset pool=$2
61 typeset fs=${3##/}
62 typeset mtpt=$4
63
64 setup_filesystem "$disk" "$pool" "$fs" "$mtpt"
65
66 log_must $CP $MYTESTFILE $mtpt/$TESTFILE0
67
68 log_must $ZPOOL export $pool
69
70 [[ -d $mtpt ]] && \
71 $RM -rf $mtpt
72 }
73
74 function cleanup_all
75 {
76 typeset -i id=0
77
78 #
79 # Try import individually if 'import -a' failed.
80 #
81 for pool in `$ZPOOL import | $GREP "pool:" | $AWK '{print $2}'`; do
82 $ZPOOL import -f $pool
83 done
84
85 for pool in `$ZPOOL import -d $DEVICE_DIR | $GREP "pool:" | $AWK '{print $2}'`; do
86 log_must $ZPOOL import -d $DEVICE_DIR -f $pool
87 done
88
89 while (( id < number )); do
90 if ! poolexists ${TESTPOOL}-$id ; then
91 (( id = id + 1 ))
92 continue
93 fi
94
95 if (( id == 0 )); then
96 log_must $ZPOOL export ${TESTPOOL}-$id
97
98 [[ -d /${TESTPOOL}-$id ]] && \
99 log_must $RM -rf /${TESTPOOL}-$id
100
101 log_must $ZPOOL import -f ${TESTPOOL}-$id $TESTPOOL
102
103 [[ -e $TESTDIR/$TESTFILE0 ]] && \
104 log_must $RM -rf $TESTDIR/$TESTFILE0
105 else
106 cleanup_filesystem "${TESTPOOL}-$id" $TESTFS
107
108 destroy_pool ${TESTPOOL}-$id
109 fi
110
111 (( id = id + 1 ))
112 done
113
114 [[ -d $ALTER_ROOT ]] && \
115 $RM -rf $ALTER_ROOT
116 }
117
118 function checksum_all #alter_root
119 {
120 typeset alter_root=$1
121 typeset -i id=0
122 typeset file
123 typeset checksum2
124
125 while (( id < number )); do
126 if (( id == 2 )); then
127 (( id = id + 1 ))
128 continue
129 fi
130
131 if (( id == 0 )); then
132 file=${alter_root}/$TESTDIR/$TESTFILE0
133 else
134 file=${alter_root}/$TESTDIR.$id/$TESTFILE0
135 fi
136 [[ ! -e $file ]] && \
137 log_fail "$file missing after import."
138
139 checksum2=$($SUM $file | $AWK '{print $1}')
140 [[ "$checksum1" != "$checksum2" ]] && \
141 log_fail "Checksums differ ($checksum1 != $checksum2)"
142
143 (( id = id + 1 ))
144 done
145
146 return 0
147 }
148
149
150 log_assert "Verify that 'zpool import -a' succeeds as root."
151
152 log_onexit cleanup_all
153
154 checksum1=$($SUM $MYTESTFILE | $AWK '{print $1}')
155
156 log_must $ZPOOL export $TESTPOOL
157 log_must $ZPOOL import $TESTPOOL ${TESTPOOL}-0
158 log_must $CP $MYTESTFILE $TESTDIR/$TESTFILE0
159 log_must $ZPOOL export ${TESTPOOL}-0
160 [[ -d /${TESTPOOL}-0 ]] && \
161 log_must $RM -rf /${TESTPOOL}-0
162
163 #
164 # setup exported pools on normal devices
165 #
166 number=1
167 while (( number <= $GROUP_NUM )); do
168 if (( number == 2)); then
169 (( number = number + 1 ))
170 continue
171 fi
172
173 setup_single_disk "${ZFS_DISK1}s${number}" \
174 "${TESTPOOL}-$number" \
175 "$TESTFS" \
176 "$TESTDIR.$number"
177
178 (( number = number + 1 ))
179 done
180
181 #
182 # setup exported pools on raw files
183 #
184 for disk in $DEVICE_FILES
185 do
186
187 setup_single_disk "$disk" \
188 "${TESTPOOL}-$number" \
189 "$TESTFS" \
190 "$TESTDIR.$number"
191
192 (( number = number + 1 ))
193 done
194
195 while (( i < ${#options[*]} )); do
196
197 log_must $ZPOOL import -d ${DEV_DSKDIR} -d $DEVICE_DIR ${options[i]} -a -f
198
199 # destroy unintentional imported pools
200 typeset exclude=`eval $ECHO \"'(${KEEP})'\"`
201 for unwantedpool in $($ZPOOL list -H -o name \
202 | $EGREP -v "$exclude" | $GREP -v $TESTPOOL); do
203 log_must $ZPOOL export $unwantedpool
204 done
205
206 if [[ -n ${options[i]} ]]; then
207 checksum_all $ALTER_ROOT
208 else
209 checksum_all
210 fi
211
212 id=0
213 while (( id < number )); do
214 if poolexists ${TESTPOOL}-$id ; then
215 log_must $ZPOOL export ${TESTPOOL}-$id
216 fi
217 (( id = id + 1 ))
218 done
219
220 (( i = i + 1 ))
221 done
222
223 log_pass "'zpool import -a' succeeds as root."