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_paths_changed.ksh
blob457eb6a14ac296f6e267c98ee14b8b4ef2dff3d2
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 even if device paths have changed.
24 # STRATEGY:
25 # 1. Create a pool.
26 # 2. Export the pool.
27 # 3. Change the paths of some of the devices.
28 # 4. Verify that we can import the pool in a healthy state.
31 verify_runnable "global"
33 log_onexit cleanup
35 function test_new_paths
37 typeset poolcreate="$1"
38 typeset pathstochange="$2"
40 log_note "$0: pool '$poolcreate', changing paths of $pathstochange."
42 log_must zpool create $TESTPOOL1 $poolcreate
44 log_must zpool export $TESTPOOL1
46 for dev in $pathstochange; do
47 log_must mv $dev "${dev}_new"
48 done
50 log_must zpool import -d $DEVICE_DIR $TESTPOOL1
51 log_must check_pool_healthy $TESTPOOL1
53 # Cleanup
54 log_must zpool destroy $TESTPOOL1
55 for dev in $pathstochange; do
56 log_must mv "${dev}_new" $dev
57 done
59 log_note ""
62 function test_swap_paths
64 typeset poolcreate="$1"
65 typeset pathtoswap1="$2"
66 typeset pathtoswap2="$3"
68 log_note "$0: pool '$poolcreate', swapping paths of $pathtoswap1" \
69 "and $pathtoswap2."
71 log_must zpool create $TESTPOOL1 $poolcreate
73 log_must zpool export $TESTPOOL1
75 log_must mv $pathtoswap2 "$pathtoswap2.tmp"
76 log_must mv $pathtoswap1 "$pathtoswap2"
77 log_must mv "$pathtoswap2.tmp" $pathtoswap1
79 log_must zpool import -d $DEVICE_DIR $TESTPOOL1
80 log_must check_pool_healthy $TESTPOOL1
82 # Cleanup
83 log_must zpool destroy $TESTPOOL1
85 log_note ""
88 test_new_paths "$VDEV0 $VDEV1" "$VDEV0 $VDEV1"
89 test_new_paths "mirror $VDEV0 $VDEV1" "$VDEV0 $VDEV1"
90 test_new_paths "$VDEV0 log $VDEV1" "$VDEV1"
91 test_new_paths "raidz $VDEV0 $VDEV1 $VDEV2" "$VDEV1"
93 test_swap_paths "$VDEV0 $VDEV1" "$VDEV0" "$VDEV1"
94 test_swap_paths "raidz $VDEV0 $VDEV1 $VDEV2" "$VDEV0" "$VDEV1"
95 test_swap_paths "mirror $VDEV0 $VDEV1 mirror $VDEV2 $VDEV3" \
96 "$VDEV0" "$VDEV2"
98 log_pass "zpool import succeeded after changing device paths."