]>
git.proxmox.com Git - mirror_zfs-debian.git/blob - tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_012_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 2009 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
29 # Copyright (c) 2012, 2016 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 # Once a pool has been exported, it should be recreated after a
39 # successful import, all the sub-filesystems within it should all be restored,
40 # include mount & share status. Verify that is true.
43 # 1. Create the test pool and hierarchical filesystems.
44 # 2. Export the test pool, or destroy the test pool,
45 # depend on testing import [-Df].
46 # 3. Import it using the various combinations.
48 # - Alternate Root Specified
49 # 4. Verify the mount & share status is restored.
52 verify_runnable
"global"
54 set -A pools
"$TESTPOOL" "$TESTPOOL1"
55 set -A devs
"" "-d $DEVICE_DIR"
56 set -A options
"" "-R $ALTER_ROOT"
57 set -A mtpts
"$TESTDIR" "$TESTDIR1"
64 while ((i
< ${#pools[*]})); do
65 if poolexists
${pools[i]}; then
66 log_must zpool
export ${pools[i]}
67 log_note
"Try to import ${devs[i]} ${pools[i]}"
68 zpool import
${devs[i]} ${pools[i]}
70 log_note
"Try to import $option ${devs[i]} ${pools[i]}"
71 zpool import
$option ${devs[i]} ${pools[i]}
74 if poolexists
${pools[i]}; then
75 is_shared
${pools[i]} && \
76 log_must zfs
set sharenfs
=off
${pools[i]}
78 ismounted
"${pools[i]}/$TESTFS" || \
79 log_must zfs mount
${pools[i]}/$TESTFS
85 destroy_pool
$TESTPOOL1
87 if datasetexists
$TESTPOOL/$TESTFS; then
88 log_must zfs destroy
-Rf $TESTPOOL/$TESTFS
90 log_must zfs create
$TESTPOOL/$TESTFS
91 log_must zfs
set mountpoint
=$TESTDIR $TESTPOOL/$TESTFS
93 [[ -d $ALTER_ROOT ]] && \
94 log_must
rm -rf $ALTER_ROOT
99 log_assert
"Verify all mount & share status of sub-filesystems within a pool \
100 can be restored after import [-Df]."
102 setup_filesystem
"$DEVICE_FILES" $TESTPOOL1 $TESTFS $TESTDIR1
103 # create a hierarchy of filesystem
104 for pool
in ${pools[@]} ; do
105 log_must zfs create
$pool/$TESTFS/$TESTCTR
106 log_must zfs create
$pool/$TESTFS/$TESTCTR/$TESTCTR1
107 log_must zfs
set canmount
=off
$pool/$TESTFS/$TESTCTR
108 log_must zfs
set canmount
=off
$pool/$TESTFS/$TESTCTR/$TESTCTR1
109 log_must zfs create
$pool/$TESTFS/$TESTCTR/$TESTFS1
110 log_must zfs create
$pool/$TESTFS/$TESTCTR/$TESTCTR1/$TESTFS1
111 log_must zfs create
$pool/$TESTFS/$TESTFS1
112 log_must zfs snapshot
$pool/$TESTFS/$TESTFS1@snap
113 log_must zfs clone
$pool/$TESTFS/$TESTFS1@snap
$pool/$TESTCLONE1
116 typeset mount_fs
="$TESTFS $TESTFS/$TESTFS1 $TESTCLONE1 \
117 $TESTFS/$TESTCTR/$TESTFS1 $TESTFS/$TESTCTR/$TESTCTR1/$TESTFS1"
118 typeset nomount_fs
="$TESTFS/$TESTCTR $TESTFS/$TESTCTR/$TESTCTR1"
122 typeset
-i nfs_share_bit
=0
123 typeset
-i guid_bit
=0
126 for option
in "" "-Df"; do
128 while ((i
< ${#pools[*]})); do
130 guid
=$
(get_pool_prop guid
$pool)
132 while ((j
< ${#options[*]})); do
133 # set sharenfs property off/on
135 while ((nfs_share_bit
<= 1)); do
137 typeset nfs_flag
="sharenfs=off"
138 if ((nfs_share_bit
== 1)); then
139 log_note
"Set sharenfs=on $pool"
140 log_must zfs
set sharenfs
=on
$pool
141 log_must is_shared
$pool
143 nfs_flag
="sharenfs=on"
145 # for every off/on nfs bit import guid/pool_name
147 while ((guid_bit
<= 1)); do
148 typeset guid_flag
="pool name"
149 if [[ -z $option ]]; then
150 log_must zpool
export $pool
152 log_must zpool destroy
$pool
156 if ((guid_bit
== 1)); then
157 log_note
"Import by guid."
158 if [[ -z $guid ]]; then
159 log_fail
"guid should "\
166 log_note
"Import with $nfs_flag and " \
168 zpool import
$option ${devs[i]} \
169 ${options[j]} $target
170 #import by GUID if import by pool name fails
171 if [[ $?
!= 0 ]]; then
172 log_note
"Possible pool name" \
173 "duplicates. Try GUID import"
175 log_must zpool import
$option \
176 ${devs[i]} ${options[j]} \
179 log_must poolexists
$pool
181 for fs
in $mount_fs; do
182 log_must ismounted
$pool/$fs
183 [[ -n $f_share ]] && \
184 log_must is_shared
$pool/$fs
187 for fs
in $nomount_fs; do
188 log_mustnot ismounted
$pool/$fs
189 log_mustnot is_shared
$pool/$fs
191 ((guid_bit
= guid_bit
+ 1))
194 if [[ -n $f_share ]]; then
195 log_must zfs
set sharenfs
=off
$pool
196 log_mustnot is_shared
$pool
198 ((nfs_share_bit
= nfs_share_bit
+ 1))
208 log_pass
"All mount & share status of sub-filesystems within a pool \
209 can be restored after import [-Df]."