]> git.proxmox.com Git - mirror_zfs.git/blob - tests/zfs-tests/tests/functional/cli_root/zpool_import/import_cachefile_device_replaced.ksh
ZTS: Fix import_cache_device_replaced
[mirror_zfs.git] / tests / zfs-tests / tests / functional / cli_root / zpool_import / import_cachefile_device_replaced.ksh
1 #!/bin/ksh -p
2
3 #
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
7 # 1.0 of the CDDL.
8 #
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.
12 #
13
14 #
15 # Copyright (c) 2016 by Delphix. All rights reserved.
16 #
17
18 . $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.kshlib
19
20 #
21 # DESCRIPTION:
22 # A pool should be importable using an outdated cachefile that is unaware
23 # of a zpool replace operation at different stages in time.
24 #
25 # STRATEGY:
26 # 1. Create a pool with some devices and an alternate cachefile.
27 # 2. Backup the cachefile.
28 # 3. Initiate device replacement, backup cachefile again and export pool.
29 # Special care must be taken so that resilvering doesn't complete
30 # before we exported the pool.
31 # 4. Verify that we can import the pool using the first cachefile backup.
32 # (Test 1. cachefile: pre-replace, pool: resilvering)
33 # 5. Wait for the resilvering to finish and export the pool.
34 # 6. Verify that we can import the pool using the first cachefile backup.
35 # (Test 2. cachefile: pre-replace, pool: post-replace)
36 # 7. Export the pool.
37 # 8. Verify that we can import the pool using the second cachefile backup.
38 # (Test 3. cachefile: resilvering, pool: post-replace)
39 #
40 # STRATEGY TO SLOW DOWN RESILVERING:
41 # 1. Reduce zfs_txg_timeout, which controls how long can we resilver for
42 # each sync.
43 # 2. Add data to pool
44 # 3. Re-import the pool so that data isn't cached
45 # 4. Use zinject to slow down device I/O
46 # 5. Trigger the resilvering
47 # 6. Use spa freeze to stop writing to the pool.
48 # 7. Clear zinject events (needed to export the pool)
49 # 8. Export the pool
50 #
51
52 verify_runnable "global"
53
54 ZFS_TXG_TIMEOUT=""
55
56 function custom_cleanup
57 {
58 # Revert zfs_txg_timeout to defaults
59 [[ -n ZFS_TXG_TIMEOUT ]] &&
60 log_must set_zfs_txg_timeout $ZFS_TXG_TIMEOUT
61
62 zinject -c all
63 log_must set_tunable64 zfs_scan_vdev_limit $ZFS_SCAN_VDEV_LIMIT_DEFAULT
64 cleanup
65 }
66
67 log_onexit custom_cleanup
68
69 function test_replacing_vdevs
70 {
71 typeset poolcreate="$1"
72 typeset replacevdev="$2"
73 typeset replaceby="$3"
74 typeset poolfinalstate="$4"
75 typeset zinjectdevices="$5"
76 typeset earlyremove="$6"
77 typeset writedata="$7"
78
79 log_note "$0: pool '$poolcreate', replace $replacevdev by $replaceby."
80
81 log_must zpool create -o cachefile=$CPATH $TESTPOOL1 $poolcreate
82
83 # Cachefile: pool in pre-replace state
84 log_must cp $CPATH $CPATHBKP
85
86 # Steps to insure resilvering happens very slowly.
87 log_must write_some_data $TESTPOOL1 $writedata
88 log_must zpool export $TESTPOOL1
89 log_must cp $CPATHBKP $CPATH
90 log_must zpool import -c $CPATH -o cachefile=$CPATH $TESTPOOL1
91 log_must set_tunable64 zfs_scan_vdev_limit $ZFS_SCAN_VDEV_LIMIT_SLOW
92 typeset device
93 for device in $zinjectdevices ; do
94 log_must zinject -d $device -D 50:1 $TESTPOOL1 > /dev/null
95 done
96 log_must zpool replace $TESTPOOL1 $replacevdev $replaceby
97
98 # Cachefile: pool in resilvering state
99 log_must cp $CPATH $CPATHBKP2
100
101 # We must disable zinject in order to export the pool, so we freeze
102 # it first to prevent writing out subsequent resilvering progress.
103 log_must zpool freeze $TESTPOOL1
104 # Confirm pool is still replacing
105 log_must pool_is_replacing $TESTPOOL1
106 log_must zinject -c all > /dev/null
107 log_must set_tunable64 zfs_scan_vdev_limit $ZFS_SCAN_VDEV_LIMIT_DEFAULT
108 log_must zpool export $TESTPOOL1
109
110 ( $earlyremove ) && log_must rm $replacevdev
111
112 ############################################################
113 # Test 1. Cachefile: pre-replace, pool: resilvering
114 ############################################################
115 log_must cp $CPATHBKP $CPATH
116 log_must zpool import -c $CPATH $TESTPOOL1
117
118 # Wait for resilvering to finish
119 log_must wait_for_pool_config $TESTPOOL1 "$poolfinalstate"
120 log_must zpool export $TESTPOOL1
121
122 ( ! $earlyremove ) && log_must rm $replacevdev
123
124 ############################################################
125 # Test 2. Cachefile: pre-replace, pool: post-replace
126 ############################################################
127 log_must zpool import -c $CPATHBKP $TESTPOOL1
128 log_must check_pool_config $TESTPOOL1 "$poolfinalstate"
129 log_must zpool export $TESTPOOL1
130
131 ############################################################
132 # Test 3. Cachefile: resilvering, pool: post-replace
133 ############################################################
134 log_must zpool import -c $CPATHBKP2 $TESTPOOL1
135 log_must check_pool_config $TESTPOOL1 "$poolfinalstate"
136
137 # Cleanup
138 log_must zpool destroy $TESTPOOL1
139 log_must rm -f $CPATH $CPATHBKP $CPATHBKP2
140 log_must mkfile $FILE_SIZE $replacevdev
141
142 log_note ""
143 }
144
145 # We set zfs_txg_timeout to 1 to reduce resilvering time at each sync.
146 ZFS_TXG_TIMEOUT=$(get_zfs_txg_timeout)
147 set_zfs_txg_timeout 1
148
149 test_replacing_vdevs "$VDEV0 $VDEV1" \
150 "$VDEV1" "$VDEV2" \
151 "$VDEV0 $VDEV2" \
152 "$VDEV0 $VDEV1" \
153 false 20
154
155 test_replacing_vdevs "mirror $VDEV0 $VDEV1" \
156 "$VDEV1" "$VDEV2" \
157 "mirror $VDEV0 $VDEV2" \
158 "$VDEV0 $VDEV1" \
159 true 10
160
161 test_replacing_vdevs "raidz $VDEV0 $VDEV1 $VDEV2" \
162 "$VDEV1" "$VDEV3" \
163 "raidz $VDEV0 $VDEV3 $VDEV2" \
164 "$VDEV0 $VDEV1 $VDEV2" \
165 true 20
166
167 set_zfs_txg_timeout $ZFS_TXG_TIMEOUT
168
169 log_pass "zpool import -c cachefile_unaware_of_replace passed."