]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zpool_replace/replace-o_ashift.ksh
Initial import from vendor-sys branch of openzfs
[FreeBSD/FreeBSD.git] / sys / contrib / openzfs / tests / zfs-tests / tests / functional / cli_root / zpool_replace / replace-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 #
26
27 . $STF_SUITE/include/libtest.shlib
28 . $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.shlib
29
30 #
31 # DESCRIPTION:
32 #       'zpool replace -o ashift=<n> ...' should work with different ashift
33 #       values.
34 #
35 # STRATEGY:
36 #       1. Create various pools with different ashift values.
37 #       2. Verify 'replace -o ashift=<n>' works only with allowed values.
38 #
39
40 verify_runnable "global"
41
42 function cleanup
43 {
44         poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
45         rm -f $disk1 $disk2
46 }
47
48 log_assert "zpool replace -o ashift=<n>' works with different ashift values"
49 log_onexit cleanup
50
51 disk1=$TEST_BASE_DIR/disk1
52 disk2=$TEST_BASE_DIR/disk2
53 log_must truncate -s $SIZE $disk1
54 log_must truncate -s $SIZE $disk2
55
56 typeset ashifts=("9" "10" "11" "12" "13" "14" "15" "16")
57 for ashift in ${ashifts[@]}
58 do
59         for cmdval in ${ashifts[@]}
60         do
61                 log_must zpool create -o ashift=$ashift $TESTPOOL1 $disk1
62                 verify_ashift $disk1 $ashift
63                 if [[ $? -ne 0 ]]
64                 then
65                         log_fail "Pool was created without setting ashift " \
66                             "value to $ashift"
67                 fi
68                 # ashift_of(replacing_disk) <= ashift_of(existing_vdev)
69                 if [[ $cmdval -le $ashift ]]
70                 then
71                         log_must zpool replace -o ashift=$cmdval $TESTPOOL1 \
72                             $disk1 $disk2
73                         verify_ashift $disk2 $ashift
74                         if [[ $? -ne 0 ]]
75                         then
76                                 log_fail "Device was replaced without " \
77                                     "setting ashift value to $ashift"
78                         fi
79                         wait_replacing $TESTPOOL1
80                 else
81                         log_mustnot zpool replace -o ashift=$cmdval $TESTPOOL1 \
82                             $disk1 $disk2
83                 fi
84                 # clean things for the next run
85                 log_must zpool destroy $TESTPOOL1
86                 log_must zpool labelclear $disk1
87                 log_must zpool labelclear $disk2
88         done
89 done
90
91 typeset badvals=("off" "on" "1" "8" "17" "1b" "ff" "-")
92 for badval in ${badvals[@]}
93 do
94         log_must zpool create $TESTPOOL1 $disk1
95         log_mustnot zpool replace -o ashift=$badval $TESTPOOL1 $disk1 $disk2
96         log_must zpool destroy $TESTPOOL1
97         log_must zpool labelclear $disk1
98         log_mustnot zpool labelclear $disk2
99 done
100
101 log_pass "zpool replace -o ashift=<n>' works with different ashift values"