fstests: convert remaining tests to SPDX license tags
[xfstests-dev.git] / tests / xfs / 294
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test 294
6 #
7 # Test readdir on fragmented multi-fsb dir blocks
8 #
9 # If the readahead map ends with a partial multi-fsb dir
10 # block, the loop at the end of xfs_dir2_leaf_readbuf() may
11 # walk off the end of the mapping array, read garbage,
12 # corrupt the loop control counter, and never return.
13 #
14 # Failure is a hang; KASAN should also catch this.
15 #
16 seq=`basename $0`
17 seqres=$RESULT_DIR/$seq
18 echo "QA output created by $seq"
19
20 here=`pwd`
21 tmp=/tmp/$$
22 status=1        # failure is the default!
23 trap "_cleanup; exit \$status" 0 1 2 3 15
24
25 _cleanup()
26 {
27         cd /
28         rm -f $tmp.*
29 }
30
31 # get standard environment, filters and checks
32 . ./common/rc
33 . ./common/filter
34
35 # remove previous $seqres.full before test
36 rm -f $seqres.full
37
38 # real QA test starts here
39
40 # Modify as appropriate.
41 _supported_fs xfs
42 _supported_os Linux
43 _require_scratch
44 _require_test_program "punch-alternating"
45
46 # We want to mkfs with a very specific geometry
47 MKFS_OPTIONS=""
48 _scratch_mkfs "-d size=512m -n size=8192 -i size=1024" >> $seqres.full 2>&1 \
49         || _fail "mkfs failed"
50 _scratch_mount
51
52 # Make a ton of mostly-empty inode clusters so we can always
53 # make more inodes
54 mkdir $SCRATCH_MNT/tmp
55 for I in `seq 1 10000`; do touch $SCRATCH_MNT/tmp/$I; done
56
57 # These mostly-empty clusters will live here:
58 mkdir $SCRATCH_MNT/clusters
59 for I in `seq 1 32 10000`; do
60         mv $SCRATCH_MNT/tmp/$I $SCRATCH_MNT/clusters;
61 done
62 rm -rf $SCRATCH_MNT/tmp
63
64 # Make our test dir with a couple blocks, should be contiguous
65 mkdir $SCRATCH_MNT/testdir
66 # roughly 20 chars per file
67 for I in `seq 1 100`; do
68         touch $SCRATCH_MNT/testdir/12345678901234567890$I;
69 done
70
71 # Now completely fragment freespace.
72 # Consume most of it:
73 $XFS_IO_PROG -f -c "falloc 0 400m" $SCRATCH_MNT/fillfile ||
74         _fail "Could not allocate space"
75
76 # File to fragment:
77 $XFS_IO_PROG -f -c "falloc 0 70m" $SCRATCH_MNT/fragfile ||
78         _fail "Could not allocate space"
79
80 df -h $SCRATCH_MNT >> $seqres.full 2>&1
81
82 # Fill remaining space; let this run to failure
83 dd if=/dev/zero of=$SCRATCH_MNT/spacefile1 oflag=direct >> $seqres.full 2>&1
84 # Fragment our all-consuming file
85 ./src/punch-alternating $SCRATCH_MNT/fragfile >> $seqres.full 2>&1
86
87 # Punching might have freed up large-ish swaths of metadata
88 # Consume hopefully any remaining contiguous freespace
89 # (and then some for good measure)
90 dd conv=fsync if=/dev/zero of=$SCRATCH_MNT/spacefile2 bs=1M count=64 >> $seqres.full 2>&1
91
92 # Now populate the directory so that it must allocate these
93 # fragmented blocks
94 for I in `seq 1 1400`; do
95         touch $SCRATCH_MNT/testdir/12345678901234567890$I;
96 done
97
98 # Now traverse that ugly thing!
99 find $SCRATCH_MNT/testdir | sort | _filter_scratch | md5sum
100
101 status=0
102 exit