]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zpool_attach/attach-o_ashift.ksh
MFV 2.0-rc2
[FreeBSD/FreeBSD.git] / sys / contrib / openzfs / tests / zfs-tests / tests / functional / cli_root / zpool_attach / attach-o_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 attach -o ashift=<n> ...' should work with different ashift
34 #       values.
35 #
36 # STRATEGY:
37 #       1. Create various pools with different ashift values.
38 #       2. Verify 'attach -o ashift=<n>' works only with allowed values.
39 #
40
41 verify_runnable "global"
42
43 function cleanup
44 {
45         log_must set_tunable64 VDEV_FILE_PHYSICAL_ASHIFT $orig_ashift
46         poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
47         rm -f $disk1 $disk2
48 }
49
50 log_assert "zpool attach -o ashift=<n>' works with different ashift values"
51 log_onexit cleanup
52
53 disk1=$TEST_BASE_DIR/disk1
54 disk2=$TEST_BASE_DIR/disk2
55 log_must truncate -s $SIZE $disk1
56 log_must truncate -s $SIZE $disk2
57
58 orig_ashift=$(get_tunable VDEV_FILE_PHYSICAL_ASHIFT)
59 #
60 # Set the file vdev's ashift to the max. Overriding
61 # the ashift using the -o ashift property should still
62 # be honored.
63 #
64 log_must set_tunable64 VDEV_FILE_PHYSICAL_ASHIFT 16
65
66 typeset ashifts=("9" "10" "11" "12" "13" "14" "15" "16")
67 for ashift in ${ashifts[@]}
68 do
69         for cmdval in ${ashifts[@]}
70         do
71                 log_must zpool create -o ashift=$ashift $TESTPOOL1 $disk1
72                 verify_ashift $disk1 $ashift
73                 if [[ $? -ne 0 ]]
74                 then
75                         log_fail "Pool was created without setting ashift " \
76                             "value to $ashift"
77                 fi
78                 # ashift_of(attached_disk) <= ashift_of(existing_vdev)
79                 if [[ $cmdval -le $ashift ]]
80                 then
81                         log_must zpool attach -o ashift=$cmdval $TESTPOOL1 \
82                             $disk1 $disk2
83                         verify_ashift $disk2 $ashift
84                         if [[ $? -ne 0 ]]
85                         then
86                                 log_fail "Device was attached without " \
87                                     "setting ashift value to $ashift"
88                         fi
89                 else
90                         log_mustnot zpool attach -o ashift=$cmdval $TESTPOOL1 \
91                             $disk1 $disk2
92                 fi
93                 # clean things for the next run
94                 log_must zpool destroy $TESTPOOL1
95                 log_must zpool labelclear $disk1
96                 log_must zpool labelclear $disk2
97         done
98 done
99
100 typeset badvals=("off" "on" "1" "8" "17" "1b" "ff" "-")
101 for badval in ${badvals[@]}
102 do
103         log_must zpool create $TESTPOOL1 $disk1
104         log_mustnot zpool attach -o ashift=$badval $TESTPOOL1 $disk1 $disk2
105         log_must zpool destroy $TESTPOOL1
106         log_must zpool labelclear $disk1
107         log_mustnot zpool labelclear $disk2
108 done
109
110 log_pass "zpool attach -o ashift=<n>' works with different ashift values"