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.
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.
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]
24 # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
29 # Copyright (c) 2013, 2016 by Delphix. All rights reserved.
32 .
$STF_SUITE/include
/libtest.shlib
36 # With 'compression' set, a file with non-power-of-2 blocksize storage space
37 # can be freed as will normally.
40 # 1. Set 'compression' or 'compress' to on or lzjb
41 # 2. Set different recordsize with ZFS filesystem
42 # 3. Repeatedly using 'randfree_file' to create a file and then free its
43 # storage space with different range, the system should work normally.
46 verify_runnable
"both"
53 function create_free_testing
#<file size> <file>
61 for start
in 0 `expr $RANDOM % $fsz`
63 (( dist
= fsz
- start
))
64 for len
in `expr $RANDOM % $dist` $dist \
65 `expr $start + $dist`; do
66 log_must randfree_file
-l fsz
-s $start \
75 log_assert
"Creating non-power-of-2 blocksize file and freeing the file \
76 storage space at will should work normally with compression setting"
80 single_blk_file
=$TESTDIR/singleblkfile.$$
81 multi_blk_file
=$TESTDIR/multiblkfile.$$
82 typeset
-i blksize
=512
87 for propname
in "compression" "compress"
89 for value
in $
(get_compress_opts zfs_compress
)
91 log_must zfs
set compression
=$value $fs
92 real_val
=$
(get_prop
$propname $fs)
93 if [[ $value == "gzip-6" ]]; then
96 [[ $real_val != $value ]] && \
97 log_fail
"Set property $propname=$value failed."
100 while (( blksize
<= 131072 )); do
101 log_must zfs
set recordsize
=$blksize $fs
103 # doing single block testing
104 (( fsize
= $RANDOM ))
105 if (( fsize
> blksize
)); then
106 (( fsize
= fsize
% blksize
))
108 if (( (fsize
% 2) == 0 )); then
109 #make sure fsize is non-power-of-2
110 (( fsize
= fsize
+ 1 ))
112 create_free_testing
$fsize $single_blk_file
114 # doing multiple blocks testing
115 avail
=$
(get_prop available
$fs)
116 (( blknum
= avail
/ blksize
))
117 # we just test <10 multi-blocks to limit testing time
118 (( blknum
= blknum
% 9 ))
119 while (( blknum
< 2 )); do
120 (( blknum
= blknum
+ $RANDOM % 9 ))
122 if (( (blknum
% 2) == 0 )); then
123 (( blknum
= blknum
+ 1 )) # keep blknum as odd
125 (( fsize
= blknum
* blksize
))
126 create_free_testing
$fsize $multi_blk_file
128 (( blksize
= blksize
* 2 ))
133 log_pass
"Creating and freeing non-power-of-2 blocksize file work as expected."