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_add/zpool_add.kshlib
30
31#
32# DESCRIPTION:
33#	'zpool add -o ashift=<n> ...' should work with different ashift
34#	values.
35#
36# STRATEGY:
37#	1. Create a pool with default values.
38#	2. Verify 'zpool add -o ashift=<n>' works with allowed values (9-16).
39#	3. Verify setting kernel tunable for file vdevs works correctly.
40#	4. Verify 'zpool add -o ashift=<n>' doesn't accept other invalid values.
41#
42
43verify_runnable "global"
44
45function cleanup
46{
47	log_must set_tunable64 VDEV_FILE_PHYSICAL_ASHIFT $orig_ashift
48	poolexists $TESTPOOL && destroy_pool $TESTPOOL
49	rm -f $disk1 $disk2
50}
51
52log_assert "zpool add -o ashift=<n>' works with different ashift values"
53log_onexit cleanup
54
55disk1=$TEST_BASE_DIR/disk1
56disk2=$TEST_BASE_DIR/disk2
57log_must mkfile $SIZE $disk1
58log_must mkfile $SIZE $disk2
59
60orig_ashift=$(get_tunable VDEV_FILE_PHYSICAL_ASHIFT)
61
62typeset ashifts=("9" "10" "11" "12" "13" "14" "15" "16")
63for ashift in ${ashifts[@]}
64do
65	log_must zpool create $TESTPOOL $disk1
66	log_must zpool add -o ashift=$ashift $TESTPOOL $disk2
67	verify_ashift $disk2 $ashift
68	if [[ $? -ne 0 ]]
69	then
70		log_fail "Device was added without setting ashift value to "\
71		    "$ashift"
72	fi
73	# clean things for the next run
74	log_must zpool destroy $TESTPOOL
75	log_must zpool labelclear $disk1
76	log_must zpool labelclear $disk2
77
78	#
79	# Make sure we can also set the ashift using the tunable.
80	#
81	log_must zpool create $TESTPOOL $disk1
82	log_must set_tunable64 VDEV_FILE_PHYSICAL_ASHIFT $ashift
83	log_must zpool add $TESTPOOL $disk2
84	verify_ashift $disk2 $ashift
85	if [[ $? -ne 0 ]]
86	then
87		log_fail "Device was added without setting ashift value to "\
88		    "$ashift"
89	fi
90	# clean things for the next run
91	log_must set_tunable64 VDEV_FILE_PHYSICAL_ASHIFT $orig_ashift
92	log_must zpool destroy $TESTPOOL
93	log_must zpool labelclear $disk1
94	log_must zpool labelclear $disk2
95done
96
97typeset badvals=("off" "on" "1" "8" "17" "1b" "ff" "-")
98for badval in ${badvals[@]}
99do
100	log_must zpool create $TESTPOOL $disk1
101	log_mustnot zpool add -o ashift="$badval" $TESTPOOL $disk2
102	# clean things for the next run
103	log_must zpool destroy $TESTPOOL
104	log_must zpool labelclear $disk1
105	log_mustnot zpool labelclear $disk2
106done
107
108log_pass "zpool add -o ashift=<n>' works with different ashift values"
109