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 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{ 47 poolexists $TESTPOOL && destroy_pool $TESTPOOL 48 rm -f $disk 49} 50 51# 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 56# 57function write_device_uberblocks # <device> <pool> 58{ 59 typeset device=$1 60 typeset pool=$2 61 62 while zdb -quuul $device | grep -q 'invalid'; do 63 sync_pool $pool true 64 done 65} 66 67# 68# Verify every label on <device> contains <count> (valid) uberblocks 69# 70function verify_device_uberblocks # <device> <count> 71{ 72 typeset device=$1 73 typeset ubcount=$2 74 75 zdb -quuul $device | awk -v ubcount=$ubcount ' 76 /Uberblock/ && ! /invalid/ { uberblocks[$0]++ } 77 END { 78 count = 0 79 for (i in uberblocks) { 80 if (uberblocks[i] != 4) { 81 printf "%s count: %s != 4\n", i, uberblocks[i] 82 exit 1 83 } 84 count++; 85 } 86 if (count != ubcount) { 87 printf "Total uberblock count: %s != %s\n", count, ubcount 88 exit 1 89 } 90 }' 91} 92 93log_assert "zpool create -o ashift=<n>' works with different ashift values" 94log_onexit cleanup 95 96disk=$(create_blockfile $SIZE) 97 98typeset ashifts=("9" "10" "11" "12" "13" "14" "15" "16") 99# since Illumos 4958 the largest uberblock is 8K so we have at least of 16/label 100typeset ubcount=("128" "128" "64" "32" "16" "16" "16" "16") 101typeset -i i=0; 102while [ $i -lt "${#ashifts[@]}" ] 103do 104 typeset ashift=${ashifts[$i]} 105 log_must zpool create -o ashift=$ashift $TESTPOOL $disk 106 typeset pprop=$(get_pool_prop ashift $TESTPOOL) 107 verify_ashift $disk $ashift 108 if [[ $? -ne 0 || "$pprop" != "$ashift" ]] 109 then 110 log_fail "Pool was created without setting ashift value to "\ 111 "$ashift (current = $pprop)" 112 fi 113 write_device_uberblocks $disk $TESTPOOL 114 log_must verify_device_uberblocks $disk ${ubcount[$i]} 115 116 # clean things for the next run 117 log_must zpool destroy $TESTPOOL 118 log_must zpool labelclear $disk 119 log_must verify_device_uberblocks $disk 0 120 ((i = i + 1)) 121done 122 123typeset badvals=("off" "on" "1" "8" "17" "1b" "ff" "-") 124for badval in ${badvals[@]} 125do 126 log_mustnot zpool create -o ashift="$badval" $TESTPOOL $disk 127done 128 129log_pass "zpool create -o ashift=<n>' works with different ashift values" 130