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 when up to 2 top-level devices are missing.
26 # 2. Write some data to the pool and checksum it.
27 # 3. Add one or more devices.
28 # 4. Write more data to the pool and checksum it.
30 # 6. Move added devices out of the devices directory.
31 # 7. Import the pool with missing devices.
32 # 8. Verify that the first batch of data is intact.
33 # 9. Verify that accessing the second batch of data doesn't suspend pool.
34 # 10. Export the pool, move back missing devices, Re-import the pool.
35 # 11. Verify that all the data is intact.
38 verify_runnable
"global"
40 function custom_cleanup
42 log_must set_spa_load_verify_metadata
1
43 log_must set_spa_load_verify_data
1
44 log_must set_zfs_max_missing_tvds
0
45 log_must
rm -rf $BACKUP_DEVICE_DIR
46 # Highly damaged pools may fail to be destroyed, so we export them.
47 poolexists
$TESTPOOL1 && log_must zpool
export $TESTPOOL1
51 log_onexit custom_cleanup
53 function test_devices_missing
55 typeset poolcreate
="$1"
57 typeset missingvdevs
="$3"
58 typeset
-i missingtvds
="$4"
60 log_note
"$0: pool '$poolcreate', adding $addvdevs, then" \
61 "moving away $missingvdevs."
63 log_must zpool create
$TESTPOOL1 $poolcreate
65 log_must generate_data
$TESTPOOL1 $MD5FILE "first"
67 log_must zpool add
$TESTPOOL1 $addvdevs
69 log_must generate_data
$TESTPOOL1 $MD5FILE2 "second"
71 log_must zpool
export $TESTPOOL1
73 log_must
mv $missingvdevs $BACKUP_DEVICE_DIR
75 # Tell zfs that it is ok to import a pool with missing top-level vdevs
76 log_must set_zfs_max_missing_tvds
$missingtvds
77 # Missing devices means that data or metadata may be corrupted.
78 (( missingtvds
> 1 )) && log_must set_spa_load_verify_metadata
0
79 log_must set_spa_load_verify_data
0
80 log_must zpool import
-o readonly=on
-d $DEVICE_DIR $TESTPOOL1
82 log_must verify_data_md5sums
$MD5FILE
84 log_note
"Try reading second batch of data, make sure pool doesn't" \
86 verify_data_md5sums
$MD5FILE >/dev
/null
2>&1
88 log_must zpool
export $TESTPOOL1
90 typeset newpaths
=$
(echo "$missingvdevs" | \
91 sed "s:$DEVICE_DIR:$BACKUP_DEVICE_DIR:g")
92 log_must
mv $newpaths $DEVICE_DIR
93 log_must set_spa_load_verify_metadata
1
94 log_must set_spa_load_verify_data
1
95 log_must set_zfs_max_missing_tvds
0
96 log_must zpool import
-d $DEVICE_DIR $TESTPOOL1
98 log_must verify_data_md5sums
$MD5FILE
99 log_must verify_data_md5sums
$MD5FILE2
102 log_must zpool destroy
$TESTPOOL1
107 log_must mkdir
$BACKUP_DEVICE_DIR
109 test_devices_missing
"$VDEV0" "$VDEV1" "$VDEV1" 1
110 test_devices_missing
"$VDEV0" "$VDEV1 $VDEV2" "$VDEV1" 1
111 test_devices_missing
"mirror $VDEV0 $VDEV1" "mirror $VDEV2 $VDEV3" \
113 test_devices_missing
"$VDEV0 log $VDEV1" "$VDEV2" "$VDEV2" 1
116 # Note that we are testing for 2 non-consecutive missing devices.
117 # Missing consecutive devices results in missing metadata. Because of
118 # Missing metadata can cause the root dataset to fail to mount.
120 test_devices_missing
"$VDEV0" "$VDEV1 $VDEV2 $VDEV3" "$VDEV1 $VDEV3" 2
122 log_pass
"zpool import succeeded with missing devices."