]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zpool_replace/replace_prop_ashift.ksh
Update openzfs to 2.0.0-rc2-g4ce06f
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zpool_replace / replace_prop_ashift.ksh
1 #!/bin/ksh -p
2 #
3 # CDDL HEADER START
4 #
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22
23 #
24 # Copyright 2017, loli10K. All rights reserved.
25 # Copyright (c) 2020 by Delphix. All rights reserved.
26 #
27
28 . $STF_SUITE/include/libtest.shlib
29 . $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.shlib
30
31 #
32 # DESCRIPTION:
33 #       'zpool replace' should use the ashift pool property value as default.
34 #
35 # STRATEGY:
36 #       1. Create a pool with default values.
37 #       2. Verify 'zpool replace' uses the ashift pool property value when
38 #          replacing an existing device.
39 #       3. Verify the default ashift value can still be overridden by manually
40 #          specifying '-o ashift=<n>' from the command line.
41 #
42
43 verify_runnable "global"
44
45 function cleanup
46 {
47         log_must set_tunable64 VDEV_FILE_PHYSICAL_ASHIFT $orig_ashift
48         poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
49         rm -f $disk1 $disk2
50 }
51
52 log_assert "'zpool replace' uses the ashift pool property value as default."
53 log_onexit cleanup
54
55 disk1=$TEST_BASE_DIR/disk1
56 disk2=$TEST_BASE_DIR/disk2
57 log_must truncate -s $SIZE $disk1
58 log_must truncate -s $SIZE $disk2
59
60 orig_ashift=$(get_tunable VDEV_FILE_PHYSICAL_ASHIFT)
61 #
62 # Set the file vdev's ashift to the max. Overriding
63 # the ashift using the -o ashift property should still
64 # be honored.
65 #
66 log_must set_tunable64 VDEV_FILE_PHYSICAL_ASHIFT 16
67
68 typeset ashifts=("9" "10" "11" "12" "13" "14" "15" "16")
69 for ashift in ${ashifts[@]}
70 do
71         for pprop in ${ashifts[@]}
72         do
73                 log_must zpool create -o ashift=$ashift $TESTPOOL1 $disk1
74                 log_must zpool set ashift=$pprop $TESTPOOL1
75                 # ashift_of(replacing_disk) <= ashift_of(existing_vdev)
76                 if [[ $pprop -le $ashift ]]
77                 then
78                         log_must zpool replace $TESTPOOL1 $disk1 $disk2
79                         wait_replacing $TESTPOOL1
80                         verify_ashift $disk2 $ashift
81                         if [[ $? -ne 0 ]]
82                         then
83                                 log_fail "Device was replaced without " \
84                                     "setting ashift value to $ashift"
85                         fi
86                 else
87                         # cannot replace if pool prop ashift > vdev ashift
88                         log_mustnot zpool replace $TESTPOOL1 $disk1 $disk2
89                         # verify we can override the pool prop value manually
90                         log_must zpool replace -o ashift=$ashift $TESTPOOL1 \
91                             $disk1 $disk2
92                         wait_replacing $TESTPOOL1
93                         verify_ashift $disk2 $ashift
94                         if [[ $? -ne 0 ]]
95                         then
96                                 log_fail "Device was replaced without " \
97                                     "setting ashift value to $ashift"
98                         fi
99                 fi
100                 # clean things for the next run
101                 log_must zpool destroy $TESTPOOL1
102                 log_must zpool labelclear $disk1
103                 log_must zpool labelclear $disk2
104         done
105 done
106
107 log_pass "'zpool replace' uses the ashift pool property value."