1 #!/bin/ksh -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 
  28 #
  29 # Copyright (c) 2013 by Delphix. All rights reserved.
  30 #
  31 
  32 . $STF_SUITE/include/libtest.shlib
  33 
  34 #
  35 # DESCRIPTION:
  36 # With 'compression' or 'compress'  set, changing filesystem blocksize cannot
  37 # cause system panic
  38 #
  39 # STRATEGY:
  40 #       1. Set 'compression' or "compress" to on
  41 #       2. Set different blocksize with ZFS filesystem
  42 #       3. Use 'mkfile' create single block and multi-block files
  43 #       4. Verify the system continued work
  44 #
  45 
  46 verify_runnable "both"
  47 
  48 function cleanup
  49 {
  50         $RM -f $TESTDIR/*
  51 }
  52 
  53 log_assert "Changing blocksize doesn't casue system panic with compression settings"
  54 log_onexit cleanup
  55 
  56 fs=$TESTPOOL/$TESTFS
  57 single_blk_file=$TESTDIR/singleblkfile.$$
  58 multi_blk_file=$TESTDIR/multiblkfile.$$
  59 typeset -i blksize=512
  60 typeset -i fsize=0
  61 typeset -i offset=0
  62 
  63 for propname in "compression" "compress"
  64 do
  65         for value in $(get_compress_opts zfs_compress)
  66         do
  67                 log_must $ZFS set $propname=$value $fs
  68                 if [[ $value == "gzip-6" ]]; then
  69                         value="gzip"
  70                 fi
  71                 real_val=$(get_prop $propname $fs)
  72                 [[ $real_val != $value ]] && \
  73                         log_fail "Set property $propname=$value failed."
  74 
  75                 (( blksize = 512 ))
  76                 while (( blksize <= 131072 )); do
  77                         log_must $ZFS set recordsize=$blksize $fs
  78                         (( offset = $RANDOM ))
  79                         if (( offset > blksize )); then
  80                                 (( offset = offset % blksize ))
  81                         fi
  82                         if (( (offset % 2) == 0 )); then
  83                                 #keep offset as non-power-of-2
  84                                 (( offset = offset + 1 ))
  85                         fi
  86                         (( fsize = offset ))
  87                         log_must $MKFILE $fsize $single_blk_file
  88                         (( fsize = blksize + offset ))
  89                         log_must $MKFILE $fsize $multi_blk_file
  90 
  91                         (( blksize = blksize * 2 ))
  92                 done
  93         done
  94 done
  95 
  96 log_pass "The system works as expected while changing blocksize with compression settings"