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_cachefile_mirror_detached.ksh
blob85ec51673b28b02a0bdf0df4e54c9a48fdd3fcd3
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 using an outdated cachefile that is unaware
23 # that a mirror was detached.
25 # STRATEGY:
26 # 1. Create a pool with some devices mirrored and an alternate cachefile.
27 # 2. Backup the cachefile.
28 # 3. Detach a mirror from the pool.
29 # 4. Export the pool.
30 # 5. Verify that we can import the pool using the backed-up cachefile.
33 verify_runnable "global"
35 log_onexit cleanup
37 function test_detach_vdev
39 typeset poolcreate="$1"
40 typeset poolcheck="$2"
42 log_note "$0: pool '$poolcreate', detach $VDEV4."
44 log_must zpool create -o cachefile=$CPATH $TESTPOOL1 $poolcreate
46 log_must cp $CPATH $CPATHBKP
48 log_must zpool detach $TESTPOOL1 $VDEV4
49 log_must rm -f $VDEV4
51 log_must zpool export $TESTPOOL1
53 log_must zpool import -c $CPATHBKP $TESTPOOL1
54 log_must check_pool_config $TESTPOOL1 "$poolcheck"
56 # Cleanup
57 log_must zpool destroy $TESTPOOL1
58 log_must rm -f $CPATH $CPATHBKP
59 log_must mkfile $FILE_SIZE $VDEV4
61 log_note ""
64 test_detach_vdev "mirror $VDEV0 $VDEV4" "$VDEV0"
65 test_detach_vdev "mirror $VDEV0 $VDEV4 mirror $VDEV1 $VDEV2" \
66 "$VDEV0 mirror $VDEV1 $VDEV2"
67 test_detach_vdev "mirror $VDEV0 $VDEV1 $VDEV4" "mirror $VDEV0 $VDEV1"
68 test_detach_vdev "$VDEV0 log mirror $VDEV1 $VDEV4" "$VDEV0 log $VDEV1"
70 log_pass "zpool import -c cachefile_unaware_of_detach passed."