Home | History | Annotate | Download | only in ext4-uninit-groups
      1 #!/bin/bash
      2 
      3 ################################################################################
      4 #                                                                              #
      5 # Copyright (c) 2009 FUJITSU LIMITED                                           #
      6 #                                                                              #
      7 # This program is free software;  you can redistribute it and#or modify        #
      8 # it under the terms of the GNU General Public License as published by         #
      9 # the Free Software Foundation; either version 2 of the License, or            #
     10 # (at your option) any later version.                                          #
     11 #                                                                              #
     12 # This program is distributed in the hope that it will be useful, but          #
     13 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY   #
     14 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License     #
     15 # for more details.                                                            #
     16 #                                                                              #
     17 # You should have received a copy of the GNU General Public License            #
     18 # along with this program;  if not, write to the Free Software                 #
     19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA      #
     20 #                                                                              #
     21 ################################################################################
     22 
     23 export TCID="ext4-uninit-groups"
     24 export TST_TOTAL=24
     25 
     26 . ext4_funcs.sh
     27 
     28 # How to age filesystem
     29 EMPTY=1
     30 SMALL=2
     31 LARGE=3
     32 
     33 age_filesystem()
     34 {
     35 	if [ $1 -eq $EMPTY ]; then
     36 		# aging, then del
     37 		ffsb ffsb-config3 > /dev/null
     38 		rm -rf mnt_point/*
     39 	elif [ $1 -eq $SMALL ]; then
     40 		# age filesystem from 0.0 to 0.2 -> 0.4 -> 0.6 -> 0.8 -> 1.0
     41 		for ((n = 3; n < 8; n++))
     42 		{
     43 			ffsb ffsb-config$n > /dev/null
     44 			mv mnt_point/data mnt_point/data$n
     45 		}
     46 	elif [ $1 -eq $LARGE ]; then
     47 		rm -rf mnt_point/*
     48 		bsize=`dumpe2fs -h $EXT4_DEV 2> /dev/null | grep 'Block size'`
     49 		bsize=`echo $bsize | awk '{ print $3 }'`
     50 		bcount=`dumpe2fs -h $EXT4_DEV 2> /dev/null | grep 'Free blocks'`
     51 		bcount=`echo $bcount | awk '{ print $3 }'`
     52 		dd if=/dev/zero of=mnt_point/tmp_dir bs=$bsize count=$bcount
     53 	else
     54 		return 1
     55 	fi
     56 
     57 	return 0
     58 }
     59 
     60 # Test uninitialized groups
     61 # $1: orlov, oldalloc
     62 # $2: delalloc
     63 # $3: flex_bg
     64 # $4: age filesystem: $EMPTY, $SMALL, $LARGE
     65 ext4_test_uninit_groups()
     66 {
     67 	echo "Test $TST_COUNT" >> ext4_uninit_groups_result.txt
     68 
     69 	mkfs.ext4 -I 256 -m 0 $EXT4_DEV >/dev/null 2>&1
     70 	if [ $? -ne 0 ]; then
     71 		tst_resm TFAIL "failed to create ext4 filesystem"
     72 		return
     73 	fi
     74 
     75 	if [ "$3" = "no_flex_bg" ]; then
     76 		flag=""
     77 	else
     78 		flag=$3
     79 	fi
     80 
     81 	tune2fs -O extents,uninit_groups,$flag $EXT4_DEV >/dev/null 2>&1
     82 
     83 	# Must run fsck after setting uninit_groups
     84 	fsck -p $EXT4_DEV >/dev/null 2>&1
     85 
     86 	mount -t ext4 -o $1,$2 $EXT4_DEV mnt_point
     87 	if [ $? -ne 0 ]; then
     88 		tst_resm TFAIL "failed to mount ext4 filesystem"
     89 		return
     90 	fi
     91 
     92 	age_filesystem $4 >> ext4_uninit_groups_result.txt 2>&1
     93 	if [ $? -ne 0 ]; then
     94 		tst_resm TFAIL "age filesystem failed"
     95 		umount mnt_point
     96 		return
     97 	fi
     98 
     99 	umount mnt_point
    100 	if [ $? -ne 0 ]; then
    101 		tst_resm TFAIL "failed to umount ext4 filesystem"
    102 		return
    103 	fi
    104 
    105 	fsck -p $EXT4_DEV >/dev/null 2>&1
    106 	if [ $? -ne 0 ]; then
    107 		tst_resm TFAIL "fsck returned failure"
    108 		return
    109 	fi
    110 
    111 	tst_resm TPASS "ext4 uninit groups test pass"
    112 }
    113 
    114 # main
    115 ext4_setup
    116 
    117 tst_test_cmds ffsb
    118 
    119 ORLOV=( "orlov" "oldalloc" )
    120 DELALLOC=( "delalloc" "nodelalloc" )
    121 FLEX_BG=( "flex_bg" "no_flex_bg" )
    122 AGING=( $EMPTY $SMALL $LARGE )
    123 
    124 
    125 for ((i = 0; i < 2; i++))
    126 {
    127 	for ((j = 0; j < 2; j++))
    128 	{
    129 		for ((k = 0; k < 2; k++))
    130 		{
    131 			for ((l = 0; l < 3; l++))
    132 			{
    133 				ext4_test_uninit_groups ${ORLOV[$i]} \
    134 							${DELALLOC[$j]} \
    135 							${FLEX_BG[$k]} \
    136 							${AGING[$l]}
    137 			}
    138 		}
    139 	}
    140 }
    141 
    142 tst_exit
    143