1#!/usr/local/bin/ksh93 -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 2007 Sun Microsystems, Inc. All rights reserved. 25# Use is subject to license terms. 26. $STF_SUITE/include/libtest.kshlib 27 28################################################################################ 29# 30# __stc_assertion_start 31# 32# ID: compress_004_pos 33# 34# DESCRIPTION: 35# With 'compression' set, a file with non-power-of-2 blocksize storage space 36# can be freed as will normally. 37# 38# STRATEGY: 39# 1. Set 'compression' or 'compress' to on or lzjb 40# 2. Set different recordsize with ZFS filesystem 41# 3. Repeatedly using 'randfree_file' to create a file and then free its 42# storage space with different range, the system should work normally. 43# 44# TESTABILITY: explicit 45# 46# TEST_AUTOMATION_LEVEL: automated 47# 48# CODING_STATUS: COMPLETED (2006-07-26) 49# 50# __stc_assertion_end 51# 52################################################################################ 53 54verify_runnable "both" 55 56function cleanup 57{ 58 $RM -f $TESTDIR/* 59} 60 61function create_free_testing #<file size> <file> 62{ 63 typeset -i fsz=$1 64 typeset file=$2 65 typeset -i start=0 66 typeset -i len=0 67 typeset -i dist=0 68 69 for start in 0 `expr $RANDOM % $fsz` 70 do 71 (( dist = fsz - start )) 72 for len in `expr $RANDOM % $dist` $dist \ 73 `expr $start + $dist`; do 74 log_must $RANDFREE_FILE -l fsz -s $start \ 75 -n $len $file 76 [[ -e $file ]] && \ 77 log_must $RM -f $file 78 done 79 done 80} 81 82 83log_assert "Creating non-power-of-2 blocksize file and freeing the file \ 84 storage space at will should work normally with compression setting" 85log_onexit cleanup 86 87fs=$TESTPOOL/$TESTFS 88single_blk_file=$TESTDIR/singleblkfile.${TESTCASE_ID} 89multi_blk_file=$TESTDIR/multiblkfile.${TESTCASE_ID} 90typeset -i blksize=512 91typeset -i fsize=0 92typeset -i avail=0 93typeset -i blknum=0 94 95for propname in "compression" "compress" 96do 97 for value in $(get_compress_opts zfs_compress) 98 do 99 log_must $ZFS set compression=$value $fs 100 real_val=$(get_prop $propname $fs) 101 if [[ $value == "gzip-6" ]]; then 102 value="gzip" 103 fi 104 [[ $real_val != $value ]] && \ 105 log_fail "Set property $propname=$value failed." 106 107 (( blksize = 512 )) 108 while (( blksize <= 131072 )); do 109 log_must $ZFS set recordsize=$blksize $fs 110 111 # doing single block testing 112 (( fsize = $RANDOM )) 113 if (( fsize > blksize )); then 114 (( fsize = fsize % blksize )) 115 fi 116 if (( (fsize % 2) == 0 )); then 117 #make sure fsize is non-power-of-2 118 (( fsize = fsize + 1 )) 119 fi 120 create_free_testing $fsize $single_blk_file 121 122 # doing multiple blocks testing 123 avail=$(get_prop available $fs) 124 (( blknum = avail / blksize )) 125 # we just test <10 multi-blocks to limit testing time 126 (( blknum = blknum % 9 )) 127 while (( blknum < 2 )); do 128 (( blknum = blknum + $RANDOM % 9 )) 129 done 130 if (( (blknum % 2) == 0 )); then 131 (( blknum = blknum + 1 )) # keep blknum as odd 132 fi 133 (( fsize = blknum * blksize )) 134 create_free_testing $fsize $multi_blk_file 135 136 (( blksize = blksize * 2 )) 137 done 138 done 139done 140 141log_pass "Creating and freeing non-power-of-2 blocksize file work as expected." 142