btrfs/012: check free size of scratch device before copying files
[xfstests-dev.git] / tests / xfs / 538
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2021 Chandan Babu R.  All Rights Reserved.
4 #
5 # FS QA Test 538
6 #
7 # Execute fsstress with bmap_alloc_minlen_extent error tag enabled.
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27 . ./common/inject
28 . ./common/populate
29
30 # remove previous $seqres.full before test
31 rm -f $seqres.full
32
33 # real QA test starts here
34
35 _supported_fs xfs
36 _require_scratch
37 _require_xfs_debug
38 _require_test_program "punch-alternating"
39 _require_xfs_io_error_injection "bmap_alloc_minlen_extent"
40
41 echo "Format and mount fs"
42 _scratch_mkfs_sized $((1024 * 1024 * 1024)) >> $seqres.full
43 _scratch_mount >> $seqres.full
44
45 # Disable realtime inherit flag (if any) on root directory so that space on data
46 # device gets fragmented rather than realtime device.
47 $XFS_IO_PROG -c 'chattr -t' $SCRATCH_MNT
48
49 bsize=$(_get_file_block_size $SCRATCH_MNT)
50
51 echo "Consume free space"
52 fillerdir=$SCRATCH_MNT/fillerdir
53 nr_free_blks=$(stat -f -c '%f' $SCRATCH_MNT)
54 nr_free_blks=$((nr_free_blks * 90 / 100))
55
56 _fill_fs $((bsize * nr_free_blks)) $fillerdir $bsize 0 >> $seqres.full 2>&1
57
58 echo "Create fragmented filesystem"
59 for dentry in $(ls -1 $fillerdir/); do
60         $here/src/punch-alternating $fillerdir/$dentry >> $seqres.full
61 done
62
63 echo "Inject bmap_alloc_minlen_extent error tag"
64 _scratch_inject_error bmap_alloc_minlen_extent 1
65
66 echo "Scale fsstress args"
67 args=$(_scale_fsstress_args -p $((LOAD_FACTOR * 75)) -n $((TIME_FACTOR * 1000)))
68
69 echo "Execute fsstress in background"
70 $FSSTRESS_PROG -d $SCRATCH_MNT $args \
71                  -f bulkstat=0 \
72                  -f bulkstat1=0 \
73                  -f fiemap=0 \
74                  -f getattr=0 \
75                  -f getdents=0 \
76                  -f getfattr=0 \
77                  -f listfattr=0 \
78                  -f mread=0 \
79                  -f read=0 \
80                  -f readlink=0 \
81                  -f readv=0 \
82                  -f stat=0 \
83                  -f aread=0 \
84                  -f dread=0 > /dev/null 2>&1
85
86 # success, all done
87 status=0
88 exit