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 https://opensource.org/licenses/CDDL-1.0.
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#
34# zpool set can modify 'ashift' property
35#
36# STRATEGY:
37# 1. Create a pool
38# 2. Verify that we can set 'ashift' only to allowed values on that pool
39#
40
41verify_runnable "global"
42
43function cleanup
44{
45	log_must set_tunable32 VDEV_FILE_PHYSICAL_ASHIFT $orig_ashift
46	destroy_pool $TESTPOOL1
47	rm -f $disk
48}
49
50typeset goodvals=("0" "9" "10" "11" "12" "13" "14" "15" "16")
51typeset badvals=("off" "on" "1" "8" "17" "1b" "ff" "-")
52
53log_onexit cleanup
54
55log_assert "zpool set can modify 'ashift' property"
56
57orig_ashift=$(get_tunable VDEV_FILE_PHYSICAL_ASHIFT)
58#
59# Set the file vdev's ashift to the max. Overriding
60# the ashift using the -o ashift property should still
61# be honored.
62#
63log_must set_tunable32 VDEV_FILE_PHYSICAL_ASHIFT 16
64
65disk=$TEST_BASE_DIR/disk
66log_must mkfile $SIZE $disk
67log_must zpool create $TESTPOOL1 $disk
68
69for ashift in ${goodvals[@]}
70do
71	log_must zpool set ashift=$ashift $TESTPOOL1
72	typeset value=$(get_pool_prop ashift $TESTPOOL1)
73	if [[ "$ashift" != "$value" ]]; then
74		log_fail "'zpool set' did not update ashift value to $ashift "\
75		    "(current = $value)"
76	fi
77done
78
79for ashift in ${badvals[@]}
80do
81	log_mustnot zpool set ashift=$ashift $TESTPOOL1
82	typeset value=$(get_pool_prop ashift $TESTPOOL1)
83	if [[ "$ashift" == "$value" ]]; then
84		log_fail "'zpool set' incorrectly set ashift value to $value"
85	fi
86done
87
88log_pass "zpool set can modify 'ashift' property"
89