]> git.proxmox.com Git - mirror_zfs.git/blob - tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_rename_001_pos.ksh
60ccc0dd6006a346377a5b5a1a9dc43249225bcb
[mirror_zfs.git] / tests / zfs-tests / tests / functional / cli_root / zpool_import / zpool_import_rename_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 2007 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 # An exported pool can be imported under a different name. Hence
39 # we test that a previously exported pool can be renamed.
40 #
41 # STRATEGY:
42 # 1. Copy a file into the default test directory.
43 # 2. Umount the default directory.
44 # 3. Export the pool.
45 # 4. Import the pool using the name ${TESTPOOL}-new,
46 # and using the various combinations.
47 # - Regular import
48 # - Alternate Root Specified
49 # 5. Verify it exists in the 'zpool list' output.
50 # 6. Verify the default file system is mounted and that the file
51 # from step (1) is present.
52 #
53
54 verify_runnable "global"
55
56 set -A pools "$TESTPOOL" "$TESTPOOL1"
57 set -A devs "" "-d $DEVICE_DIR"
58 set -A options "" "-R $ALTER_ROOT"
59 set -A mtpts "$TESTDIR" "$TESTDIR1"
60
61
62 function cleanup
63 {
64 typeset -i i=0
65 while (( i < ${#pools[*]} )); do
66 if poolexists "${pools[i]}-new" ; then
67 log_must $ZPOOL export "${pools[i]}-new"
68
69 [[ -d /${pools[i]}-new ]] && \
70 log_must $RM -rf /${pools[i]}-new
71
72 log_must $ZPOOL import ${devs[i]} \
73 "${pools[i]}-new" ${pools[i]}
74 fi
75
76 datasetexists "${pools[i]}" || \
77 log_must $ZPOOL import ${devs[i]} ${pools[i]}
78
79 ismounted "${pools[i]}/$TESTFS" || \
80 log_must $ZFS mount ${pools[i]}/$TESTFS
81
82 [[ -e ${mtpts[i]}/$TESTFILE0 ]] && \
83 log_must $RM -rf ${mtpts[i]}/$TESTFILE0
84
85 ((i = i + 1))
86
87 done
88
89 cleanup_filesystem $TESTPOOL1 $TESTFS $TESTDIR1
90
91 destroy_pool $TESTPOOL1
92
93 [[ -d $ALTER_ROOT ]] && \
94 log_must $RM -rf $ALTER_ROOT
95 }
96
97 log_onexit cleanup
98
99 log_assert "Verify that an imported pool can be renamed."
100
101 setup_filesystem "$DEVICE_FILES" $TESTPOOL1 $TESTFS $TESTDIR1
102 checksum1=$($SUM $MYTESTFILE | $AWK '{print $1}')
103
104 typeset -i i=0
105 typeset -i j=0
106 typeset basedir
107
108 while (( i < ${#pools[*]} )); do
109 guid=$(get_config ${pools[i]} pool_guid)
110 log_must $CP $MYTESTFILE ${mtpts[i]}/$TESTFILE0
111
112 log_must $ZFS umount ${mtpts[i]}
113
114 j=0
115 while (( j < ${#options[*]} )); do
116 log_must $ZPOOL export ${pools[i]}
117
118 [[ -d /${pools[i]} ]] && \
119 log_must $RM -rf /${pools[i]}
120
121 typeset target=${pools[i]}
122 if (( RANDOM % 2 == 0 )) ; then
123 target=$guid
124 log_note "Import by guid."
125 fi
126
127 log_must $ZPOOL import ${devs[i]} ${options[j]} \
128 $target ${pools[i]}-new
129
130 log_must poolexists "${pools[i]}-new"
131
132 log_must ismounted ${pools[i]}-new/$TESTFS
133
134 basedir=${mtpts[i]}
135 [[ -n ${options[j]} ]] && \
136 basedir=$ALTER_ROOT/${mtpts[i]}
137
138 [[ ! -e $basedir/$TESTFILE0 ]] && \
139 log_fail "$basedir/$TESTFILE0 missing after import."
140
141 checksum2=$($SUM $basedir/$TESTFILE0 | $AWK '{print $1}')
142 [[ "$checksum1" != "$checksum2" ]] && \
143 log_fail "Checksums differ ($checksum1 != $checksum2)"
144
145 log_must $ZPOOL export "${pools[i]}-new"
146
147 [[ -d /${pools[i]}-new ]] && \
148 log_must $RM -rf /${pools[i]}-new
149
150 target=${pools[i]}-new
151 if (( RANDOM % 2 == 0 )) ; then
152 target=$guid
153 fi
154 log_must $ZPOOL import ${devs[i]} $target ${pools[i]}
155
156 ((j = j + 1))
157 done
158
159 ((i = i + 1))
160 done
161
162 log_pass "Successfully imported and renamed a ZPOOL"