1*b73ccab0SMike Gerdts#!/bin/ksh -p 2*b73ccab0SMike Gerdts# 3*b73ccab0SMike Gerdts# This file and its contents are supplied under the terms of the 4*b73ccab0SMike Gerdts# Common Development and Distribution License ("CDDL"), version 1.0. 5*b73ccab0SMike Gerdts# You may only use this file in accordance with the terms of version 6*b73ccab0SMike Gerdts# 1.0 of the CDDL. 7*b73ccab0SMike Gerdts# 8*b73ccab0SMike Gerdts# A full copy of the text of the CDDL should have accompanied this 9*b73ccab0SMike Gerdts# source. A copy of the CDDL is also available via the Internet at 10*b73ccab0SMike Gerdts# http://www.illumos.org/license/CDDL. 11*b73ccab0SMike Gerdts# 12*b73ccab0SMike Gerdts 13*b73ccab0SMike Gerdts# 14*b73ccab0SMike Gerdts# Copyright 2019 Joyent, Inc. 15*b73ccab0SMike Gerdts# 16*b73ccab0SMike Gerdts 17*b73ccab0SMike Gerdts. $STF_SUITE/include/libtest.shlib 18*b73ccab0SMike Gerdts. $STF_SUITE/tests/functional/refreserv/refreserv.cfg 19*b73ccab0SMike Gerdts 20*b73ccab0SMike Gerdts# 21*b73ccab0SMike Gerdts# DESCRIPTION: 22*b73ccab0SMike Gerdts# raidz refreservation=auto accounts for extra parity and skip blocks 23*b73ccab0SMike Gerdts# 24*b73ccab0SMike Gerdts# STRATEGY: 25*b73ccab0SMike Gerdts# 1. Create a pool with a single raidz vdev 26*b73ccab0SMike Gerdts# 2. For each block size [512b, 1k, 128k] or [4k, 8k, 128k] 27*b73ccab0SMike Gerdts# - create a volume 28*b73ccab0SMike Gerdts# - fully overwrite it 29*b73ccab0SMike Gerdts# - verify that referenced is less than or equal to reservation 30*b73ccab0SMike Gerdts# - destroy the volume 31*b73ccab0SMike Gerdts# 3. Destroy the pool 32*b73ccab0SMike Gerdts# 4. Recreate the pool with one more disk in the vdev, then repeat steps 33*b73ccab0SMike Gerdts# 2 and 3. 34*b73ccab0SMike Gerdts# 5. Repeat all steps above for raidz2 and raidz3. 35*b73ccab0SMike Gerdts# 36*b73ccab0SMike Gerdts# NOTES: 37*b73ccab0SMike Gerdts# 1. This test will use up to 14 disks but can cover the key concepts with 38*b73ccab0SMike Gerdts# 5 disks. 39*b73ccab0SMike Gerdts# 2. If the disks are a mixture of 4Kn and 512n/512e, failures are likely. 40*b73ccab0SMike Gerdts# 41*b73ccab0SMike Gerdts 42*b73ccab0SMike Gerdtsverify_runnable "global" 43*b73ccab0SMike Gerdts 44*b73ccab0SMike Gerdtstypeset -a alldisks=($DISKS) 45*b73ccab0SMike Gerdts 46*b73ccab0SMike Gerdts# The larger the volsize, the better zvol_volsize_to_reservation() is at 47*b73ccab0SMike Gerdts# guessing the right number. At 10M on ashift=12, the estimate may be over 26% 48*b73ccab0SMike Gerdts# too high. 49*b73ccab0SMike Gerdtsvolsize=100 50*b73ccab0SMike Gerdts 51*b73ccab0SMike Gerdtsfunction cleanup 52*b73ccab0SMike Gerdts{ 53*b73ccab0SMike Gerdts default_cleanup_noexit 54*b73ccab0SMike Gerdts default_setup_noexit "${alldisks[0]}" 55*b73ccab0SMike Gerdts} 56*b73ccab0SMike Gerdts 57*b73ccab0SMike Gerdtslog_assert "raidz refreservation=auto accounts for extra parity and skip blocks" 58*b73ccab0SMike Gerdtslog_onexit cleanup 59*b73ccab0SMike Gerdts 60*b73ccab0SMike Gerdtspoolexists "$TESTPOOL" && log_must zpool destroy "$TESTPOOL" 61*b73ccab0SMike Gerdts 62*b73ccab0SMike Gerdts# Testing tiny block sizes on ashift=12 pools causes so much size inflation 63*b73ccab0SMike Gerdts# that small test disks may fill before creating small volumes. However, 64*b73ccab0SMike Gerdts# testing 512b and 1K blocks on ashift=9 pools is an ok approximation for 65*b73ccab0SMike Gerdts# testing the problems that arise from 4K and 8K blocks on ashift=12 pools. 66*b73ccab0SMike Gerdtsbps=$(prtvtoc /dev/rdsk/${alldisks[0]} | 67*b73ccab0SMike Gerdts awk '$NF == "bytes/sector" { print $2; exit 0 }') 68*b73ccab0SMike Gerdtslog_must test "$bps" -eq 512 -o "$bps" -eq 4096 69*b73ccab0SMike Gerdtscase "$bps" in 70*b73ccab0SMike Gerdts512) 71*b73ccab0SMike Gerdts allshifts=(9 10 17) 72*b73ccab0SMike Gerdts maxpct=151 73*b73ccab0SMike Gerdts ;; 74*b73ccab0SMike Gerdts4096) 75*b73ccab0SMike Gerdts allshifts=(12 13 17) 76*b73ccab0SMike Gerdts maxpct=110 77*b73ccab0SMike Gerdts ;; 78*b73ccab0SMike Gerdts*) 79*b73ccab0SMike Gerdts log_fail "bytes/sector != (512|4096)" 80*b73ccab0SMike Gerdts ;; 81*b73ccab0SMike Gerdtsesac 82*b73ccab0SMike Gerdtslog_note "Testing in ashift=${allshifts[0]} mode" 83*b73ccab0SMike Gerdts 84*b73ccab0SMike Gerdts# This loop handles all iterations of steps 1 through 4 described in strategy 85*b73ccab0SMike Gerdts# comment above, 86*b73ccab0SMike Gerdtsfor parity in 1 2 3; do 87*b73ccab0SMike Gerdts raid=raidz$parity 88*b73ccab0SMike Gerdts 89*b73ccab0SMike Gerdts # Ensure we hit scenarios with and without skip blocks 90*b73ccab0SMike Gerdts for ndisks in $((parity * 2)) $((parity * 2 + 1)); do 91*b73ccab0SMike Gerdts typeset -a disks=(${alldisks[0..$((ndisks - 1))]}) 92*b73ccab0SMike Gerdts 93*b73ccab0SMike Gerdts if (( ${#disks[@]} < ndisks )); then 94*b73ccab0SMike Gerdts log_note "Too few disks to test $raid-$ndisks" 95*b73ccab0SMike Gerdts continue 96*b73ccab0SMike Gerdts fi 97*b73ccab0SMike Gerdts 98*b73ccab0SMike Gerdts log_must zpool create "$TESTPOOL" "$raid" "${disks[@]}" 99*b73ccab0SMike Gerdts 100*b73ccab0SMike Gerdts for bits in "${allshifts[@]}"; do 101*b73ccab0SMike Gerdts vbs=$((1 << bits)) 102*b73ccab0SMike Gerdts log_note "Testing $raid-$ndisks volblocksize=$vbs" 103*b73ccab0SMike Gerdts 104*b73ccab0SMike Gerdts vol=$TESTPOOL/$TESTVOL 105*b73ccab0SMike Gerdts log_must zfs create -V ${volsize}m \ 106*b73ccab0SMike Gerdts -o volblocksize=$vbs "$vol" 107*b73ccab0SMike Gerdts log_must dd if=/dev/zero of=/dev/zvol/dsk/$vol \ 108*b73ccab0SMike Gerdts bs=1024k count=$volsize 109*b73ccab0SMike Gerdts sync 110*b73ccab0SMike Gerdts 111*b73ccab0SMike Gerdts ref=$(zfs get -Hpo value referenced "$vol") 112*b73ccab0SMike Gerdts refres=$(zfs get -Hpo value refreservation "$vol") 113*b73ccab0SMike Gerdts log_must test -n "$ref" 114*b73ccab0SMike Gerdts log_must test -n "$refres" 115*b73ccab0SMike Gerdts 116*b73ccab0SMike Gerdts typeset -F2 deltapct=$((refres * 100.0 / ref)) 117*b73ccab0SMike Gerdts log_note "$raid-$ndisks refreservation $refres" \ 118*b73ccab0SMike Gerdts "is $deltapct% of reservation $res" 119*b73ccab0SMike Gerdts 120*b73ccab0SMike Gerdts log_must test "$ref" -le "$refres" 121*b73ccab0SMike Gerdts log_must test "$deltapct" -le $maxpct 122*b73ccab0SMike Gerdts 123*b73ccab0SMike Gerdts log_must zfs destroy "$vol" 124*b73ccab0SMike Gerdts done 125*b73ccab0SMike Gerdts 126*b73ccab0SMike Gerdts log_must zpool destroy "$TESTPOOL" 127*b73ccab0SMike Gerdts done 128*b73ccab0SMike Gerdtsdone 129*b73ccab0SMike Gerdts 130*b73ccab0SMike Gerdtslog_pass "raidz refreservation=auto accounts for extra parity and skip blocks" 131