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 | egrep '^(\s+)?Uberblock' | 89 egrep -v 'invalid$' | nawk \ 90 -v ubcount=$ubcount '{ uberblocks[$0]++; } 91 END { for (i in uberblocks) { 92 count++; 93 if (uberblocks[i] != 4) { exit 1; } 94 } 95 if (count != ubcount) { exit 1; } }' 96 97 return $? 98} 99 100log_assert "zpool create -o ashift=<n>' works with different ashift values" 101log_onexit cleanup 102 103disk=$TEST_BASE_DIR/$FILEDISK0 104log_must mkfile $SIZE $disk 105 106typeset ashifts=("9" "10" "11" "12" "13" "14" "15" "16") 107# since Illumos 4958 the largest uberblock is 8K so we have at least of 16/label 108typeset ubcount=("128" "128" "64" "32" "16" "16" "16" "16") 109typeset -i i=0; 110while [ $i -lt "${#ashifts[@]}" ] 111do 112 typeset ashift=${ashifts[$i]} 113 log_must zpool create -o ashift=$ashift $TESTPOOL $disk 114 typeset pprop=$(get_pool_prop ashift $TESTPOOL) 115 verify_ashift $disk $ashift 116 if [[ $? -ne 0 || "$pprop" != "$ashift" ]] 117 then 118 log_fail "Pool was created without setting ashift value to "\ 119 "$ashift (current = $pprop)" 120 fi 121 # force 128 txg sync to fill the uberblock ring 122 log_must eval "txg_sync $TESTPOOL 128" 123 verify_device_uberblocks $disk ${ubcount[$i]} 124 if [[ $? -ne 0 ]] 125 then 126 log_fail "Pool was created with unexpected number of uberblocks" 127 fi 128 # clean things for the next run 129 log_must zpool destroy $TESTPOOL 130 log_must zpool labelclear $disk 131 log_must eval "verify_device_uberblocks $disk 0" 132 ((i = i + 1)) 133done 134 135typeset badvals=("off" "on" "1" "8" "17" "1b" "ff" "-") 136for badval in ${badvals[@]} 137do 138 log_mustnot zpool create -o ashift="$badval" $TESTPOOL $disk 139done 140 141log_pass "zpool create -o ashift=<n>' works with different ashift values" 142