]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zpool_import/import_cachefile_shared_device.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zpool_import / import_cachefile_shared_device.ksh
1 #!/bin/ksh -p
2
3 #
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.
8 #
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.
12 #
13
14 #
15 # Copyright (c) 2016 by Delphix. All rights reserved.
16 #
17
18 . $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.kshlib
19
20 #
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.
24 #
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.
34 #
35
36 verify_runnable "global"
37
38 function custom_cleanup
39 {
40         destroy_pool $TESTPOOL2
41         cleanup
42 }
43
44 log_onexit custom_cleanup
45
46 function dev_checksum
47 {
48         typeset dev="$1"
49         typeset checksum
50
51         log_note "Compute checksum of '$dev'"
52
53         checksum=$(md5digest $dev)
54         if [[ $? -ne 0 ]]; then
55                 log_fail "Failed to compute checksum of '$dev'"
56                 return 1
57         fi
58
59         echo "$checksum"
60         return 0
61 }
62
63 function test_shared_device
64 {
65         typeset pool1="$1"
66         typeset pool2="$2"
67         typeset sharedvdev="$3"
68         typeset importflags="${4:-}"
69
70         log_note "$0: pool1 '$pool1', pool2 '$pool2' takes $sharedvdev."
71
72         log_must zpool create -o cachefile=$CPATH $TESTPOOL1 $pool1
73
74         log_must cp $CPATH $CPATHBKP
75
76         log_must zpool export $TESTPOOL1
77
78         log_must zpool create -f $TESTPOOL2 $pool2
79
80         log_must zpool export $TESTPOOL2
81
82         typeset checksum1=$(dev_checksum $sharedvdev)
83
84         log_must zpool import -c $CPATHBKP $importflags $TESTPOOL1
85
86         log_must write_some_data $TESTPOOL1 2
87
88         log_must zpool destroy $TESTPOOL1
89
90         typeset checksum2=$(dev_checksum $sharedvdev)
91
92         if [[ $checksum1 == $checksum2 ]]; then
93                 log_pass "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."
97         fi
98
99         # Cleanup
100         log_must zpool import -d $DEVICE_DIR $TESTPOOL2
101         log_must zpool destroy $TESTPOOL2
102         log_must rm -f $CPATH $CPATHBKP
103
104         log_note ""
105 }
106
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"
112
113 log_pass "Pool doesn't write to a device it doesn't own anymore."