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 not try to write to a device that doesn't belong to it
23 # anymore, even if the device is in its cachefile.
26 # 1. Create pool1 with some devices and an alternate cachefile.
27 # 2. Backup the cachefile.
29 # 4. Create pool2 using a device that belongs to pool1.
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
44 log_onexit custom_cleanup
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'"
63 function test_shared_device
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"
95 log_fail
"Device has been modified by original pool." \
96 "Checksum mismatch: $checksum1 != $checksum2."
100 log_must zpool import
-d $DEVICE_DIR $TESTPOOL2
101 log_must zpool destroy
$TESTPOOL2
102 log_must
rm -f $CPATH $CPATHBKP
107 test_shared_device
"mirror $VDEV0 $VDEV1" "mirror $VDEV1 $VDEV2" "$VDEV1"
108 test_shared_device
"mirror $VDEV0 $VDEV1 $VDEV2" "mirror $VDEV2 $VDEV3" \
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."