]> git.proxmox.com Git - mirror_zfs-debian.git/blob - tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_002_pos.ksh
New upstream version 0.7.2
[mirror_zfs-debian.git] / tests / zfs-tests / tests / functional / cli_root / zpool_import / zpool_import_002_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, 2016 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 an exported pool cannot be imported
39 # more than once.
40 #
41 # STRATEGY:
42 # 1. Populate the default test directory and unmount it.
43 # 2. Export the default test pool.
44 # 3. Import it using the various combinations.
45 # - Regular import
46 # - Alternate Root Specified
47 # 4. Verify it shows up under 'zpool list'.
48 # 5. Verify it contains a file.
49 # 6. Attempt to import it for a second time. Verify this fails.
50 #
51
52 verify_runnable "global"
53
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"
58
59
60 function cleanup
61 {
62 typeset -i i=0
63 while (( i < ${#pools[*]} )); do
64 poolexists ${pools[i]} && \
65 log_must zpool export ${pools[i]}
66
67 datasetexists "${pools[i]}/$TESTFS" || \
68 log_must zpool import ${devs[i]} ${pools[i]}
69
70 ismounted "${pools[i]}/$TESTFS" || \
71 log_must zfs mount ${pools[i]}/$TESTFS
72
73 [[ -e ${mtpts[i]}/$TESTFILE0 ]] && \
74 log_must rm -rf ${mtpts[i]}/$TESTFILE0
75
76 ((i = i + 1))
77 done
78
79 cleanup_filesystem $TESTPOOL1 $TESTFS
80
81 destroy_pool $TESTPOOL1
82
83 [[ -d $ALTER_ROOT ]] && \
84 log_must rm -rf $ALTER_ROOT
85 }
86
87 log_onexit cleanup
88
89 log_assert "Verify that an exported pool cannot be imported more than once."
90
91 setup_filesystem "$DEVICE_FILES" $TESTPOOL1 $TESTFS $TESTDIR1
92
93 checksum1=$(sum $MYTESTFILE | awk '{print $1}')
94
95 typeset -i i=0
96 typeset -i j=0
97 typeset basedir
98
99 while (( i < ${#pools[*]} )); do
100 guid=$(get_config ${pools[i]} pool_guid)
101
102 log_must cp $MYTESTFILE ${mtpts[i]}/$TESTFILE0
103
104 log_must zfs umount ${mtpts[i]}
105
106 j=0
107 while (( j < ${#options[*]} )); do
108 log_must zpool export ${pools[i]}
109
110 typeset target=${pools[i]}
111 if (( RANDOM % 2 == 0 )) ; then
112 target=$guid
113 log_note "Import by guid."
114 fi
115
116 log_must zpool import ${devs[i]} ${options[j]} $target
117
118 log_must poolexists ${pools[i]}
119
120 log_must ismounted ${pools[i]}/$TESTFS
121
122 basedir=${mtpts[i]}
123 [[ -n ${options[j]} ]] && \
124 basedir=$ALTER_ROOT/${mtpts[i]}
125
126 [[ ! -e $basedir/$TESTFILE0 ]] && \
127 log_fail "$basedir/$TESTFILE0 missing after import."
128
129 checksum2=$(sum $basedir/$TESTFILE0 | awk '{print $1}')
130 [[ "$checksum1" != "$checksum2" ]] && \
131 log_fail "Checksums differ ($checksum1 != $checksum2)"
132
133 log_mustnot zpool import ${devs[i]} $target
134
135 ((j = j + 1))
136 done
137
138 ((i = i + 1))
139
140 done
141
142 log_pass "Unable to import the same pool twice as expected."