]>
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
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.
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.
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]
24 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
29 # Copyright (c) 2012 by Delphix. All rights reserved.
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
38 # Verify that 'zpool import -a' succeeds as root.
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.
47 verify_runnable
"global"
49 set -A options
"" "-R $ALTER_ROOT"
57 function setup_single_disk
#disk #pool #fs #mtpt
64 setup_filesystem
"$disk" "$pool" "$fs" "$mtpt"
66 log_must
$CP $MYTESTFILE $mtpt/$TESTFILE0
68 log_must
$ZPOOL export $pool
79 # Try import individually if 'import -a' failed.
81 for pool
in `$ZPOOL import | $GREP "pool:" | $AWK '{print $2}'`; do
82 $ZPOOL import
-f $pool
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
89 while (( id
< number
)); do
90 if ! poolexists
${TESTPOOL}-$id ; then
95 if (( id
== 0 )); then
96 log_must
$ZPOOL export ${TESTPOOL}-$id
98 [[ -d /${TESTPOOL}-$id ]] && \
99 log_must
$RM -rf /${TESTPOOL}-$id
101 log_must
$ZPOOL import
-f ${TESTPOOL}-$id $TESTPOOL
103 [[ -e $TESTDIR/$TESTFILE0 ]] && \
104 log_must
$RM -rf $TESTDIR/$TESTFILE0
106 cleanup_filesystem
"${TESTPOOL}-$id" $TESTFS
108 destroy_pool
${TESTPOOL}-$id
114 [[ -d $ALTER_ROOT ]] && \
118 function checksum_all
#alter_root
120 typeset alter_root
=$1
125 while (( id
< number
)); do
126 if (( id
== 2 )); then
131 if (( id
== 0 )); then
132 file=${alter_root}/$TESTDIR/$TESTFILE0
134 file=${alter_root}/$TESTDIR.
$id/$TESTFILE0
136 [[ ! -e $file ]] && \
137 log_fail
"$file missing after import."
139 checksum2
=$
($SUM $file |
$AWK '{print $1}')
140 [[ "$checksum1" != "$checksum2" ]] && \
141 log_fail
"Checksums differ ($checksum1 != $checksum2)"
150 log_assert
"Verify that 'zpool import -a' succeeds as root."
152 log_onexit cleanup_all
154 checksum1
=$
($SUM $MYTESTFILE |
$AWK '{print $1}')
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
164 # setup exported pools on normal devices
167 while (( number
<= $GROUP_NUM )); do
168 if (( number
== 2)); then
169 (( number
= number
+ 1 ))
173 setup_single_disk
"${ZFS_DISK1}s${number}" \
174 "${TESTPOOL}-$number" \
178 (( number
= number
+ 1 ))
182 # setup exported pools on raw files
184 for disk
in $DEVICE_FILES
187 setup_single_disk
"$disk" \
188 "${TESTPOOL}-$number" \
192 (( number
= number
+ 1 ))
195 while (( i
< ${#options[*]} )); do
197 log_must
$ZPOOL import
-d ${DEV_DSKDIR} -d $DEVICE_DIR ${options[i]} -a -f
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
206 if [[ -n ${options[i]} ]]; then
207 checksum_all
$ALTER_ROOT
213 while (( id
< number
)); do
214 if poolexists
${TESTPOOL}-$id ; then
215 log_must
$ZPOOL export ${TESTPOOL}-$id
223 log_pass
"'zpool import -a' succeeds as root."