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