9075 Improve ZFS pool import/load process and corrupted pool recovery
[unleashed.git] / usr / src / test / zfs-tests / tests / functional / cli_root / zpool_import / import_devices_missing.ksh
blob3f45ada6ee98d9255de86497033440d3cd9ef193
1 #!/usr/bin/ksh -p
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.
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
21 # DESCRIPTION:
22 # A pool should be importable when up to 2 top-level devices are missing.
24 # STRATEGY:
25 # 1. Create a pool.
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.
29 # 5. Export the pool.
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
48 cleanup
51 log_onexit custom_cleanup
53 function test_devices_missing
55 typeset poolcreate="$1"
56 typeset addvdevs="$2"
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" \
85 "get suspended."
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
101 # Cleanup
102 log_must zpool destroy $TESTPOOL1
104 log_note ""
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" \
112 "$VDEV2 $VDEV3" 1
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."