generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 324
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2013 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. generic/324
6 #
7 # Sanity check for defrag utility.
8 #
9 . ./common/preamble
10 _begin_fstest auto fsr quick defrag
11
12 PIDS=""
13
14 # Import common functions.
15 . ./common/filter
16 . ./common/defrag
17
18 # real QA test starts here
19 _require_scratch
20 _require_defrag
21 _require_xfs_io_command "falloc"
22
23 _workout()
24 {
25         nr=$1
26         echo "Defragment file with $nr * 2 fragments"
27         # Create sparse file
28         for ((i=0;i<nr;i++))
29         do
30                 $XFS_IO_PROG -f -c "falloc $((409600*i)) 4k"  \
31                         $SCRATCH_MNT/test.$nr >> $seqres.full 2>&1
32         done
33         # Fill holes for half of range , as result file will contain nr*1.5 fragments
34         $XFS_IO_PROG -c "falloc 0 $((204800*nr))"  \
35             $SCRATCH_MNT/test.$nr | _filter_xfs_io
36         # Data wrilte will convert extetns to inialized ones
37         for ((i=0;i<nr;i++))
38         do
39                 patt=`printf "0x%x" $i`
40                 $XFS_IO_PROG -c "pwrite -S $patt $((i*123400)) 1234" \
41                         $SCRATCH_MNT/test.$nr | _filter_xfs_io
42         done
43         _defrag --min_before $nr --max_before $((nr*4)) \
44                 --min_after 1 $SCRATCH_MNT/test.$nr
45 }
46
47 # Actual testing starting from here
48 _scratch_mkfs  >> $seqres.full 2>&1
49 _scratch_mount
50 _workout 10
51 _workout 250
52 _workout 1000
53 status=0