xref: /freebsd/tests/sys/cddl/zfs/tests/compression/compress_003_pos.ksh (revision 22cf89c938886d14f5796fc49f9f020c23ea8eaf)
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_003_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_003_pos
36#
37# DESCRIPTION:
38# With 'compression' or 'compress'  set, changing filesystem blocksize cannot
39# cause system panic
40#
41# STRATEGY:
42#	1. Set 'compression' or "compress" to on
43#	2. Set different blocksize with ZFS filesystem
44#	3. Use 'mkfile' create single block and multi-block files
45#	4. Verify the system continued work
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
64log_assert "Changing blocksize doesn't casue system panic with compression settings"
65log_onexit cleanup
66
67fs=$TESTPOOL/$TESTFS
68single_blk_file=$TESTDIR/singleblkfile.${TESTCASE_ID}
69multi_blk_file=$TESTDIR/multiblkfile.${TESTCASE_ID}
70typeset -i blksize=512
71typeset -i fsize=0
72typeset -i offset=0
73
74for propname in "compression" "compress"
75do
76	for value in $(get_compress_opts zfs_compress)
77	do
78		log_must $ZFS set $propname=$value $fs
79		if [[ $value == "gzip-6" ]]; then
80			value="gzip"
81		fi
82		real_val=$(get_prop $propname $fs)
83		[[ $real_val != $value ]] && \
84			log_fail "Set property $propname=$value failed."
85
86		(( blksize = 512 ))
87		while (( blksize <= 131072 )); do
88			log_must $ZFS set recordsize=$blksize $fs
89			(( offset = $RANDOM ))
90			if (( offset > blksize )); then
91				(( offset = offset % blksize ))
92			fi
93			if (( (offset % 2) == 0 )); then
94				#keep offset as non-power-of-2
95				(( offset = offset + 1 ))
96			fi
97			(( fsize = offset ))
98			log_must $MKFILE $fsize $single_blk_file
99			(( fsize = blksize + offset ))
100			log_must $MKFILE $fsize $multi_blk_file
101
102			(( blksize = blksize * 2 ))
103		done
104	done
105done
106
107log_pass "The system works as expected while changing blocksize with compression settings"
108