]> git.proxmox.com Git - mirror_zfs-debian.git/blame - tests/zfs-tests/tests/functional/cli_root/zpool_create/create-o_ashift.ksh
New upstream version 0.7.9
[mirror_zfs-debian.git] / tests / zfs-tests / tests / functional / cli_root / zpool_create / create-o_ashift.ksh
CommitLineData
cae5b340
AX
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 (c) 2017 Datto 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{
42f7b73b 47 destroy_pool $TESTPOOL
cae5b340
AX
48 log_must rm -f $disk
49}
50
51#
42f7b73b
AX
52# Fill the uberblock ring in every <device> label: we do this by committing
53# TXGs to the provided <pool> until every slot contains a valid uberblock.
54# NOTE: We use 'zpool sync' here because we can't force it via sync(1) like on
55# illumos
cae5b340 56#
42f7b73b 57function write_device_uberblocks # <device> <pool>
cae5b340 58{
42f7b73b
AX
59 typeset device=$1
60 typeset pool=$2
cae5b340 61
42f7b73b 62 while [ "$(zdb -quuul $device | grep -c 'invalid')" -ne 0 ]
cae5b340 63 do
42f7b73b 64 sync_pool $pool true
cae5b340
AX
65 done
66}
67
68#
42f7b73b 69# Verify every label on <device> contains <count> (valid) uberblocks
cae5b340 70#
42f7b73b 71function verify_device_uberblocks # <device> <count>
cae5b340
AX
72{
73 typeset device=$1
74 typeset ubcount=$2
75
76 zdb -quuul $device | egrep '^(\s+)?Uberblock' |
42f7b73b
AX
77 awk -v ubcount=$ubcount 'BEGIN { count=0 } { uberblocks[$0]++; }
78 END {
79 for (i in uberblocks) {
80 if (i ~ /invalid/) { continue; }
81 if (uberblocks[i] != 4) { exit 1; }
82 count++;
83 }
84 if (count != ubcount) { exit 1; }
85 }'
cae5b340
AX
86
87 return $?
88}
89
90log_assert "zpool create -o ashift=<n>' works with different ashift values"
91log_onexit cleanup
92
93disk=$TEST_BASE_DIR/$FILEDISK0
94log_must mkfile $SIZE $disk
95
96typeset ashifts=("9" "10" "11" "12" "13" "14" "15" "16")
97# since Illumos 4958 the largest uberblock is 8K so we have at least of 16/label
98typeset ubcount=("128" "128" "64" "32" "16" "16" "16" "16")
99typeset -i i=0;
100while [ $i -lt "${#ashifts[@]}" ]
101do
102 typeset ashift=${ashifts[$i]}
103 log_must zpool create -o ashift=$ashift $TESTPOOL $disk
104 typeset pprop=$(get_pool_prop ashift $TESTPOOL)
105 verify_ashift $disk $ashift
106 if [[ $? -ne 0 || "$pprop" != "$ashift" ]]
107 then
108 log_fail "Pool was created without setting ashift value to "\
109 "$ashift (current = $pprop)"
110 fi
42f7b73b 111 write_device_uberblocks $disk $TESTPOOL
cae5b340
AX
112 verify_device_uberblocks $disk ${ubcount[$i]}
113 if [[ $? -ne 0 ]]
114 then
115 log_fail "Pool was created with unexpected number of uberblocks"
116 fi
117 # clean things for the next run
118 log_must zpool destroy $TESTPOOL
119 log_must zpool labelclear $disk
120 log_must eval "verify_device_uberblocks $disk 0"
121 ((i = i + 1))
122done
123
124typeset badvals=("off" "on" "1" "8" "17" "1b" "ff" "-")
125for badval in ${badvals[@]}
126do
127 log_mustnot zpool create -o ashift="$badval" $TESTPOOL $disk
128done
129
130log_pass "zpool create -o ashift=<n>' works with different ashift values"