xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_create/create-o_ashift.ksh (revision 85f4cb87104c72587029a6e0f1663332c85ba118)
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 2016, loli10K. All rights reserved.
25# Copyright 2019 Joyent, Inc.
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 create -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 -o ashift=<n> works only with allowed values (9-16).
39#	   Also verify that the lowest number of uberblocks in a label is 16 and
40#	   smallest uberblock size is 8K even with higher ashift values.
41#
42
43verify_runnable "global"
44
45function cleanup
46{
47	poolexists $TESTPOOL && destroy_pool $TESTPOOL
48	log_must rm -f $disk
49}
50
51#
52# FIXME: Ugly hack to force a $1 number of txg syncs.
53# This is used on Linux because we can't force it via sync(1) like on Illumos.
54# This could eventually (an hopefully) be replaced by a 'zpool sync' command.
55# $1 pool name
56# $2 number of txg syncs
57#
58function txg_sync
59{
60	typeset pool=$1
61	typeset count=$2
62	typeset -i i=0;
63
64	while [ $i -lt $count ]
65	do
66		zfs snapshot $pool@sync$$$i
67		if [[ $? -ne 0 ]]
68		then
69			log_fail "Failed to sync pool $pool (snapshot $i)"
70			return 1
71		fi
72		((i = i + 1))
73	done
74
75	return 0
76}
77
78#
79# Verify device $1 labels contains $2 valid uberblocks in every label
80# $1 device
81# $2 uberblocks count
82#
83function verify_device_uberblocks
84{
85	typeset device=$1
86	typeset ubcount=$2
87
88        zdb -quuul $device | awk -v ubcount=$ubcount '
89            /Uberblock/ && ! /invalid/ { uberblocks[$0]++ }
90            END {
91                count = 0
92                for (i in uberblocks) {
93                    if (uberblocks[i] != 4) {
94                        printf "%s count: %s != 4\n", i, uberblocks[i]
95                        exit 1
96                    }
97                    count++;
98                }
99                if (count != ubcount) {
100                    printf "Total uberblock count: %s != %s\n", count, ubcount
101                    exit 1
102                }
103            }'
104
105	return $?
106}
107
108log_assert "zpool create -o ashift=<n>' works with different ashift values"
109log_onexit cleanup
110
111disk=$TEST_BASE_DIR/$FILEDISK0
112log_must mkfile $SIZE $disk
113
114typeset ashifts=("9" "10" "11" "12" "13" "14" "15" "16")
115# since Illumos 4958 the largest uberblock is 8K so we have at least of 16/label
116typeset ubcount=("128" "128" "64" "32" "16" "16" "16" "16")
117typeset -i i=0;
118while [ $i -lt "${#ashifts[@]}" ]
119do
120	typeset ashift=${ashifts[$i]}
121	log_must zpool create -o ashift=$ashift $TESTPOOL $disk
122	typeset pprop=$(get_pool_prop ashift $TESTPOOL)
123	verify_ashift $disk $ashift
124	if [[ $? -ne 0 || "$pprop" != "$ashift" ]]
125	then
126		log_fail "Pool was created without setting ashift value to "\
127		    "$ashift (current = $pprop)"
128	fi
129	# force 128 txg sync to fill the uberblock ring
130	log_must eval "txg_sync $TESTPOOL 128"
131	verify_device_uberblocks $disk ${ubcount[$i]}
132	if [[ $? -ne 0 ]]
133	then
134		log_fail "Pool was created with unexpected number of uberblocks"
135	fi
136	# clean things for the next run
137	log_must zpool destroy $TESTPOOL
138	log_must zpool labelclear $disk
139	log_must eval "verify_device_uberblocks $disk 0"
140	((i = i + 1))
141done
142
143typeset badvals=("off" "on" "1" "8" "17" "1b" "ff" "-")
144for badval in ${badvals[@]}
145do
146	log_mustnot zpool create -o ashift="$badval" $TESTPOOL $disk
147done
148
149log_pass "zpool create -o ashift=<n>' works with different ashift values"
150