xref: /freebsd/tests/sys/cddl/zfs/tests/compression/compress_003_pos.ksh (revision f39bffc62c1395bde25d152c7f68fdf7cbaab414)
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# $FreeBSD$
24
25#
26# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)compress_003_pos.ksh	1.3	07/06/06 SMI"
30#
31. $STF_SUITE/include/libtest.kshlib
32
33################################################################################
34#
35# __stc_assertion_start
36#
37# ID: compress_003_pos
38#
39# DESCRIPTION:
40# With 'compression' or 'compress'  set, changing filesystem blocksize cannot
41# cause system panic
42#
43# STRATEGY:
44#	1. Set 'compression' or "compress" to on
45#	2. Set different blocksize with ZFS filesystem
46#	3. Use 'mkfile' create single block and multi-block files
47#	4. Verify the system continued work
48#
49# TESTABILITY: explicit
50#
51# TEST_AUTOMATION_LEVEL: automated
52#
53# CODING_STATUS: COMPLETED (2006-07-26)
54#
55# __stc_assertion_end
56#
57################################################################################
58
59verify_runnable "both"
60
61function cleanup
62{
63	$RM -f $TESTDIR/*
64}
65
66log_assert "Changing blocksize doesn't casue system panic with compression settings"
67log_onexit cleanup
68
69fs=$TESTPOOL/$TESTFS
70single_blk_file=$TESTDIR/singleblkfile.${TESTCASE_ID}
71multi_blk_file=$TESTDIR/multiblkfile.${TESTCASE_ID}
72typeset -i blksize=512
73typeset -i fsize=0
74typeset -i offset=0
75
76for propname in "compression" "compress"
77do
78	for value in $(get_compress_opts zfs_compress)
79	do
80		log_must $ZFS set $propname=$value $fs
81		if [[ $value == "gzip-6" ]]; then
82			value="gzip"
83		fi
84		real_val=$(get_prop $propname $fs)
85		[[ $real_val != $value ]] && \
86			log_fail "Set property $propname=$value failed."
87
88		(( blksize = 512 ))
89		while (( blksize <= 131072 )); do
90			log_must $ZFS set recordsize=$blksize $fs
91			(( offset = $RANDOM ))
92			if (( offset > blksize )); then
93				(( offset = offset % blksize ))
94			fi
95			if (( (offset % 2) == 0 )); then
96				#keep offset as non-power-of-2
97				(( offset = offset + 1 ))
98			fi
99			(( fsize = offset ))
100			log_must $MKFILE $fsize $single_blk_file
101			(( fsize = blksize + offset ))
102			log_must $MKFILE $fsize $multi_blk_file
103
104			(( blksize = blksize * 2 ))
105		done
106	done
107done
108
109log_pass "The system works as expected while changing blocksize with compression settings"
110