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' should use the ashift pool property value as default.
33#
34# STRATEGY:
35#	1. Create a pool with default values.
36#	2. Verify 'zpool replace' uses the ashift pool property value when
37#	   replacing an existing device.
38#	3. Verify the default ashift value can still be overridden by manually
39#	   specifying '-o ashift=<n>' from the command line.
40#
41
42verify_runnable "global"
43
44function cleanup
45{
46	poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
47	log_must rm -f $disk1 $disk2
48}
49
50log_assert "'zpool replace' uses the ashift pool property value as default."
51log_onexit cleanup
52
53disk1=$TEST_BASE_DIR/$FILEDISK0
54disk2=$TEST_BASE_DIR/$FILEDISK1
55log_must truncate -s $SIZE $disk1
56log_must truncate -s $SIZE $disk2
57
58typeset ashifts=("9" "10" "11" "12" "13" "14" "15" "16")
59for ashift in ${ashifts[@]}
60do
61	for pprop in ${ashifts[@]}
62	do
63		log_must zpool create -o ashift=$ashift $TESTPOOL1 $disk1
64		log_must zpool set ashift=$pprop $TESTPOOL1
65		# ashift_of(replacing_disk) <= ashift_of(existing_vdev)
66		if [[ $pprop -le $ashift ]]
67		then
68			log_must zpool replace $TESTPOOL1 $disk1 $disk2
69			wait_replacing $TESTPOOL1
70			verify_ashift $disk2 $ashift
71			if [[ $? -ne 0 ]]
72			then
73				log_fail "Device was replaced without " \
74				    "setting ashift value to $ashift"
75			fi
76		else
77			# cannot replace if pool prop ashift > vdev ashift
78			log_mustnot zpool replace $TESTPOOL1 $disk1 $disk2
79			# verify we can override the pool prop value manually
80			log_must zpool replace -o ashift=$ashift $TESTPOOL1 \
81			    $disk1 $disk2
82			wait_replacing $TESTPOOL1
83			verify_ashift $disk2 $ashift
84			if [[ $? -ne 0 ]]
85			then
86				log_fail "Device was replaced without " \
87				    "setting ashift value to $ashift"
88			fi
89		fi
90		# clean things for the next run
91		log_must zpool destroy $TESTPOOL1
92		log_must zpool labelclear $disk1
93		log_must zpool labelclear $disk2
94	done
95done
96
97log_pass "'zpool replace' uses the ashift pool property value."
98