fstests: transport two ext4 tests from LTP
[xfstests-dev.git] / tests / ext4 / 045
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2020 SUSE Linux Products GmbH.  All Rights Reserved.
4 #
5 # FS QA Test No. 045
6 #
7 # Test subdirectory limit of ext4.
8 # We create more than 65000 subdirectories on the ext4 filesystem.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1       # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 SHORT_DIR=1
20 LONG_DIR=2
21
22 _cleanup()
23 {
24        cd /
25        rm -f $tmp.*
26 }
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/filter
31
32 # remove previous $seqres.full before test
33 rm -f $seqres.full
34
35 # real QA test starts here
36 _supported_fs ext4
37 _supported_os Linux
38
39 _require_scratch
40 _require_test_program "t_create_short_dirs"
41 _require_test_program "t_create_long_dirs"
42 _require_dumpe2fs "$DUMPE2FS_PROG" dumpe2fs
43
44 echo "Silence is golden"
45
46 # Run a test case
47 # $1: Number of directories to create
48 # $2: create short dir or long dir
49 # $3: parent directory
50 workout()
51 {
52        local dir_name_len=""
53        if [ $2 -eq $SHORT_DIR ]; then
54                dir_name_len="short name"
55        else
56                dir_name_len="long name"
57        fi
58
59        echo "Num of dirs to create: $1, Dir name len: $dir_name_len, " \
60                "Parent dir: $3" >> $seqres.full
61
62        _scratch_mkfs "-O extent,dir_nlink,dir_index -I 256" >> $seqres.full 2>&1
63        _scratch_mount
64
65        # create directories
66        mkdir -p $3 2> /dev/null
67
68        if [ $2 -eq $SHORT_DIR ]; then
69                $here/src/t_create_short_dirs $1 $3
70        else
71                $here/src/t_create_long_dirs $1 $3
72        fi
73
74        if [ $? -ne 0 ]; then
75                nr_dirs=`ls $3 | wc -l`
76                echo "Failed to create directories - $nr_dirs"
77                _scratch_unmount
78                return
79        fi
80
81        # delete directories
82        cd $3
83        ls | xargs rmdir
84        if [ $? -ne 0 ]; then
85                echo "Failed to remove directories in $3"
86                cd - > /dev/null
87                _scratch_unmount
88                return
89        fi
90        cd - > /dev/null
91        _scratch_unmount
92
93        # check dir_nlink is set
94        $DUMPE2FS_PROG -h $SCRATCH_DEV 2>> $seqres.full | grep '^Filesystem features' | grep -q dir_nlink
95        if [ $? -ne 0 ]; then
96                echo "Feature dir_nlink is not set, please check $seqres.full for detail"
97                return
98        fi
99 }
100
101 # main
102 DIR_NUM=65537
103 DIR_LEN=( $SHORT_DIR $LONG_DIR )
104 PARENT_DIR="$SCRATCH_MNT/subdir"
105
106 for ((i = 0; i < 2; i++)); do
107        workout $DIR_NUM ${DIR_LEN[$i]} $PARENT_DIR
108 done
109
110 status=0
111 exit