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## Author: Li Zefan <lizf@cn.fujitsu.com> ## 22## Miao Xie <miaox@cn.fujitsu.com> ## 23## ## 24################################################################################ 25 26 27export TCID="ext4-subdir-limit" 28export TST_TOTAL=10 29 30. ext4_funcs.sh 31 32SHORT_DIR=1 33LONG_DIR=2 34 35FAIL=1 36PASS=0 37 38prev_block_size=-1 39prev_result=$FAIL 40 41# Run a test case 42# $1: Number of directories to create 43# $2: create short dir or long dir 44# $3: parent directory 45# $4: filesystem block size 46ext4_run_case() 47{ 48 local dir_name_len= 49 50 if [ $2 -eq $SHORT_DIR ]; then 51 dir_name_len="short name" 52 else 53 dir_name_len="long name" 54 fi 55 56 tst_resm TINFO "Num of dirs to create: $1, Dir name len: $dir_name_len, " \ 57 "Parent dir: $3, Block size: $4" 58 59 # only mkfs if block size has been changed, 60 # or previous case failed 61 if [ $prev_result -ne $PASS -o $4 -ne $prev_block_size ]; then 62 mkfs.ext4 -b $4 -I 256 $EXT4_DEV >/dev/null 2>&1 63 if [ $? -ne 0 ]; then 64 tst_resm TFAIL "failed to create ext4 filesystem" 65 return 66 fi 67 prev_block_size=$4 68 69 tune2fs -O extents $EXT4_DEV >/dev/null 2>&1 70 fi 71 72 prev_result=$FAIL 73 74 # mount ext4 filesystem 75 mount -t ext4 $EXT4_DEV mnt_point 76 if [ $? -ne 0 ]; then 77 tst_resm TFAIL "failed to mount ext4 filesystem" 78 return 79 fi 80 81 # create directories 82 mkdir -p $3 2> /dev/null 83 84 if [ $2 -eq $SHORT_DIR ]; then 85 create_short_dirs $1 $3 86 else 87 create_long_dirs $1 $3 88 fi 89 90 if [ $? -ne 0 ]; then 91 nr_dirs=`ls $3 | wc -l` 92 tst_resm TFAIL "failed to create directories - $nr_dirs" 93 umount mnt_point 94 return 95 fi 96 97 # delete directories 98 cd $3 99 ls | xargs rmdir 100 if [ $? -ne 0 ]; then 101 tst_resm TFAIL "failed to remove directories" 102 cd - 103 umount mnt_point 104 return 105 fi 106 cd - 107 108 # unmount ext4 filesystem 109 umount mnt_point 110 if [ $? -ne 0 ]; then 111 tst_resm TFAIL "failed to umount ext4 filesystem" 112 return 113 fi 114 115 # run fsck to make sure the filesystem has no errors 116 e2fsck -p $EXT4_DEV >/dev/null 2>&1 117 if [ $? -ne 0 ]; then 118 tst_resm TFAIL "fsck: the filesystem has errors" 119 return 120 fi 121 122 # check dir_nlink is set 123 dumpe2fs $EXT4_DEV 2> /dev/null | grep '^Filesystem features' | grep -q dir_nlink 124 if [ $? -ne 0 ]; then 125 tst_resm TFAIL "feature dir_nlink is not set" 126 return 127 fi 128 129 prev_result=$PASS 130 tst_resm TPASS "ext4 subdir limit test pass" 131} 132 133# main 134ext4_setup 135 136DIR_LEN=( $SHORT_DIR $LONG_DIR ) 137PARENT_DIR=( "mnt_point" "mnt_point/sub" ) 138BLOCK_SIZE=( 1024 2048 4096 ) 139 140for ((i = 0; i < 3; i++)) 141{ 142 for ((j = 0; j < 2; j++)) 143 { 144 for ((k = 0; k < 2; k++)) 145 { 146 if [ ${DIR_LEN[$k]} -eq $LONG_DIR -a \ 147 ${BLOCK_SIZE[$i]} -eq 1024 ]; then 148 continue 149 fi 150 ext4_run_case 65537 ${DIR_LEN[$k]} ${PARENT_DIR[$j]} \ 151 ${BLOCK_SIZE[$i]} 152 } 153 } 154} 155 156tst_exit 157