4 # This file and its contents are supplied under the terms of the
5 # Common Development and Distribution License ("CDDL"), version 1.0.
6 # You may only use this file in accordance with the terms of version
9 # A full copy of the text of the CDDL should have accompanied this
10 # source. A copy of the CDDL is also available via the Internet at
11 # http://www.illumos.org/license/CDDL.
15 # Copyright (c) 2016 by Delphix. All rights reserved.
18 .
$STF_SUITE/tests
/functional
/cli_root
/zpool_import
/zpool_import.kshlib
22 # A pool should be importable using an outdated cachefile that is unaware
23 # that one or more vdevs were removed.
26 # 1. Create a pool with some devices and an alternate cachefile.
27 # 2. Backup the cachefile.
28 # 3. Remove device(s) from the pool and remove them.
29 # 4. (Optionally) Add device(s) to pool.
31 # 6. Verify that we can import the pool using the backed-up cachefile.
34 verify_runnable
"global"
36 function custom_cleanup
41 log_onexit custom_cleanup
43 function test_remove_vdev
45 typeset poolcreate
="$1"
46 typeset removevdev
="$2"
47 typeset poolcheck
="$3"
49 log_note
"$0: pool '$poolcreate', remove $2."
51 log_must zpool create
-o cachefile
=$CPATH $TESTPOOL1 $poolcreate
53 log_must
cp $CPATH $CPATHBKP
55 log_must zpool remove
$TESTPOOL1 $removevdev
56 log_must wait_for_pool_config
$TESTPOOL1 "$poolcheck"
57 log_must
rm $removevdev
59 log_must zpool
export $TESTPOOL1
61 log_must zpool import
-c $CPATHBKP $TESTPOOL1
62 log_must check_pool_config
$TESTPOOL1 "$poolcheck"
65 log_must zpool destroy
$TESTPOOL1
66 log_must
rm -f $CPATH $CPATHBKP
67 log_must mkfile
$FILE_SIZE $removevdev
73 # We have to remove top-level non-log vdevs one by one, else there is a high
74 # chance pool will report busy and command will fail for the second vdev.
76 function test_remove_two_vdevs
79 log_must zpool create
-o cachefile
=$CPATH $TESTPOOL1 \
80 $VDEV0 $VDEV1 $VDEV2 $VDEV3 $VDEV4
82 log_must
cp $CPATH $CPATHBKP
84 log_must zpool remove
$TESTPOOL1 $VDEV4
85 log_must wait_for_pool_config
$TESTPOOL1 \
86 "$VDEV0 $VDEV1 $VDEV2 $VDEV3"
87 log_must zpool remove
$TESTPOOL1 $VDEV3
88 log_must wait_for_pool_config
$TESTPOOL1 "$VDEV0 $VDEV1 $VDEV2"
89 log_must
rm $VDEV3 $VDEV4
91 log_must zpool
export $TESTPOOL1
93 log_must zpool import
-c $CPATHBKP $TESTPOOL1
94 log_must check_pool_config
$TESTPOOL1 "$VDEV0 $VDEV1 $VDEV2"
97 log_must zpool destroy
$TESTPOOL1
98 log_must
rm -f $CPATH $CPATHBKP
99 log_must mkfile
$FILE_SIZE $VDEV3 $VDEV4
105 # We want to test the case where a whole created by a log device is filled
106 # by a regular device
108 function test_remove_log_then_add_vdev
111 log_must zpool create
-o cachefile
=$CPATH $TESTPOOL1 \
112 $VDEV0 $VDEV1 $VDEV2 log
$VDEV3
114 log_must
cp $CPATH $CPATHBKP
116 log_must zpool remove
$TESTPOOL1 $VDEV1
117 log_must wait_for_pool_config
$TESTPOOL1 "$VDEV0 $VDEV2 log $VDEV3"
118 log_must zpool remove
$TESTPOOL1 $VDEV3
119 log_must check_pool_config
$TESTPOOL1 "$VDEV0 $VDEV2"
120 log_must
rm $VDEV1 $VDEV3
121 log_must zpool add
$TESTPOOL1 $VDEV4
123 log_must zpool
export $TESTPOOL1
125 log_must zpool import
-c $CPATHBKP $TESTPOOL1
126 log_must check_pool_config
$TESTPOOL1 "$VDEV0 $VDEV2 $VDEV4"
129 log_must zpool destroy
$TESTPOOL1
130 log_must
rm -f $CPATH $CPATHBKP
131 log_must mkfile
$FILE_SIZE $VDEV1 $VDEV3
136 test_remove_vdev
"$VDEV0 $VDEV1 $VDEV2" "$VDEV2" "$VDEV0 $VDEV1"
137 test_remove_vdev
"$VDEV0 $VDEV1 $VDEV2" "$VDEV1" "$VDEV0 $VDEV2"
138 test_remove_vdev
"$VDEV0 log $VDEV1" "$VDEV1" "$VDEV0"
139 test_remove_vdev
"$VDEV0 log $VDEV1 $VDEV2" "$VDEV1 $VDEV2" "$VDEV0"
140 test_remove_vdev
"$VDEV0 $VDEV1 $VDEV2 log $VDEV3" "$VDEV2" \
141 "$VDEV0 $VDEV1 log $VDEV3"
142 test_remove_two_vdevs
143 test_remove_log_then_add_vdev
145 log_pass
"zpool import -c cachefile_unaware_of_remove passed."