1 #! /usr/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 # The program to saturate a filesystem with disk/inodes
  28 
  29 [[ -n $DEBUG ]] && [[ $DEBUG != 0 ]] && set -x
  30 
  31 NAME=$(basename $0)
  32 DIR=$(dirname $0)
  33 
  34 Usage="Usage: $0 fs-to-saturate\n"
  35 
  36 if (( $# < 1 )); then
  37         echo $Usage
  38         exit 99
  39 fi
  40 
  41 fs=$1
  42 mntpt=$(zfs list -H $fs | awk '{print $NF}')
  43 if [[ $mntpt == $1 && $? == 0 ]]; then
  44         fs=$(zfs list -H $fs | awk '{print $1}')
  45         [[ $? != 0 ]] && echo "ERROR: Can not get zfs name" && exit 1
  46         TestZFS=1
  47 else
  48         TestZFS=0
  49 fi
  50 
  51 SDIR=${1}/sat_dir
  52 [[ ! -d $SDIR ]] && mkdir -m 0777 $SDIR
  53 
  54 integer Inodes i=0 j=0 Disks=0 Bigf=0 kbleft=0
  55 
  56 # create a zero byte file in the directory
  57 rm -f $SDIR/zerobyte.file
  58 > $SDIR/zerobyte.file
  59 
  60 if [[ $TestZFS == 0 ]]; then
  61         # UFS
  62         # First fill up inodes first
  63         Inodes=$(df -e $SDIR | tail -1 | awk '{print $2}')
  64         while (( i <= Inodes )); do
  65                 cp $SDIR/zerobyte.file $SDIR/Newfile.$i
  66                 ls $SDIR/Newfile.$i > /dev/null 2>&1
  67                 [[ $? == 0 ]] && let i+=1 || break
  68         done
  69 
  70         # Now fillup the disk.
  71         # first fill with MB ...
  72         i=1
  73         Disks=$(df -b $SDIR | tail -1 | awk '{print $2}')
  74         let Bigf=Disks/1024
  75         rm $SDIR/Newfile.$i
  76         (( Bigf > 0 )) && mkfile ${Bigf}m $SDIR/Newfile.$i || touch $SDIR/Newfile.$i
  77         # then fill the KB ...
  78         let kbleft=Disks%1024-1
  79         let i+=1
  80         rm $SDIR/Newfile.$i
  81         mkfile ${kbleft}k $SDIR/Newfile.$i
  82         # finally fill the Byte ... (at most 1023B)
  83         while (( j < 1023 )); do
  84                 echo "A\c" >> $SDIR/Newfile.$i
  85                 [[ $? != 0 ]] && break
  86                 let j+=1
  87         done
  88 else
  89         # ZFS
  90         Disks=$(zfs get -pHo value available $fs)
  91         if [[ $? != 0 ]]; then
  92                 echo "ERROR: Can not get zfs size"
  93                 exit 1
  94         fi
  95         mkfile ${Disks}b $SDIR/Newfile
  96 fi
  97 
  98 exit 0