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