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_shared_device.ksh
blob66225c11b93e4fac0073b7139ff9d0585c256a1e
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 not try to write to a device that doesn't belong to it
23 # anymore, even if the device is in its cachefile.
25 # STRATEGY:
26 # 1. Create pool1 with some devices and an alternate cachefile.
27 # 2. Backup the cachefile.
28 # 3. Export pool1.
29 # 4. Create pool2 using a device that belongs to pool1.
30 # 5. Export pool2.
31 # 6. Compute checksum of the shared device.
32 # 7. Import pool1 and write some data to it.
33 # 8. Verify that the checksum of the shared device hasn't changed.
36 verify_runnable "global"
38 function custom_cleanup
40 destroy_pool $TESTPOOL2
41 cleanup
44 log_onexit custom_cleanup
46 function dev_checksum
48 typeset dev="$1"
49 typeset checksum
51 log_note "Compute checksum of '$dev'"
53 checksum=$(md5sum $dev)
54 if [[ $? -ne 0 ]]; then
55 log_fail "Failed to compute checksum of '$dev'"
56 return 1
59 echo "$checksum"
60 return 0
63 function test_shared_device
65 typeset pool1="$1"
66 typeset pool2="$2"
67 typeset sharedvdev="$3"
68 typeset importflags="${4:-}"
70 log_note "$0: pool1 '$pool1', pool2 '$pool2' takes $sharedvdev."
72 log_must zpool create -o cachefile=$CPATH $TESTPOOL1 $pool1
74 log_must cp $CPATH $CPATHBKP
76 log_must zpool export $TESTPOOL1
78 log_must zpool create -f $TESTPOOL2 $pool2
80 log_must zpool export $TESTPOOL2
82 typeset checksum1=$(dev_checksum $sharedvdev)
84 log_must zpool import -c $CPATHBKP $importflags $TESTPOOL1
86 log_must write_some_data $TESTPOOL1 2
88 log_must zpool destroy $TESTPOOL1
90 typeset checksum2=$(dev_checksum $sharedvdev)
92 if [[ $checksum1 == $checksum2 ]]; then
93 log_pos "Device hasn't been modified by original pool"
94 else
95 log_fail "Device has been modified by original pool." \
96 "Checksum mismatch: $checksum1 != $checksum2."
99 # Cleanup
100 log_must zpool import -d $DEVICE_DIR $TESTPOOL2
101 log_must zpool destroy $TESTPOOL2
102 log_must rm -f $CPATH $CPATHBKP
104 log_note ""
107 test_shared_device "mirror $VDEV0 $VDEV1" "mirror $VDEV1 $VDEV2" "$VDEV1"
108 test_shared_device "mirror $VDEV0 $VDEV1 $VDEV2" "mirror $VDEV2 $VDEV3" \
109 "$VDEV2"
110 test_shared_device "raidz $VDEV0 $VDEV1 $VDEV2" "$VDEV2" "$VDEV2"
111 test_shared_device "$VDEV0 log $VDEV1" "$VDEV2 log $VDEV1" "$VDEV1" "-m"
113 log_pass "Pool doesn't write to a device it doesn't own anymore."