fsx/fsstress: round blocksize properly
[xfstests-dev.git] / tests / btrfs / 013
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2013 Fusion IO.  All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/013
6 #
7 # Regression test for balance with prealloc extents.  This checks to make sure
8 # we are balacing prealloc'ed extents properly by making sure we don't have any
9 # csum errors.  Unfortunately this manifests itself with no csum which means
10 # userspace doesn't get an error when reading the file back so we have to grok
11 # dmesg to see if there was a csum error.
12 #
13 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19
20 status=1        # failure is the default!
21
22 _cleanup()
23 {
24         rm -f $tmp.*
25 }
26
27 trap "_cleanup ; exit \$status" 0 1 2 3 15
28
29 # get standard environment, filters and checks
30 . ./common/rc
31 . ./common/filter
32
33 # real QA test starts here
34 _supported_fs btrfs
35 _require_scratch
36 _require_xfs_io_command "falloc"
37
38 rm -f $seqres.full
39
40 _scratch_mkfs > /dev/null 2>&1
41 _scratch_mount
42
43 nr_csum_no_found=$(dmesg | grep -c "no csum found")
44 nr_csum_failed=$(dmesg | grep -c "csum failed")
45
46 _check_csum_error()
47 {
48         new_csum_no_found=$(dmesg | grep -c "no csum found")
49         new_csum_failed=$(dmesg | grep -c "csum failed")
50
51         if [ $nr_csum_no_found -eq $new_csum_no_found -a \
52              $nr_csum_failed -eq $new_csum_failed ]; then
53                 return 0
54         fi
55         return 1
56 }
57 $XFS_IO_PROG -f -c "falloc 0 1M" -c "pwrite 16k 8k" -c "fsync" \
58         $SCRATCH_MNT/foo > $seqres.full 2>&1
59 _run_btrfs_balance_start $SCRATCH_MNT >> $seqres.full
60 _scratch_unmount
61 _scratch_mount
62 $XFS_IO_PROG -c "pread 0 1M" $SCRATCH_MNT/foo >> $seqres.full 2>&1 || \
63         _fail "pread failed"
64
65 # This sucks but unfortunately it is the only way to be sure something didn't go
66 # wrong.
67 _check_csum_error || _fail "csum detected, please check dmesg"
68
69 echo "Silence is golden"
70 status=0 ; exit