fstests: check for filesystem FS_IOC_FSSETXATTR support
[xfstests-dev.git] / tests / xfs / 198
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 198
6 #
7 # Test fragmentation after a lot of random CoW:
8 # - Create two reflinked files.  Set extsz hint on second file.
9 # - Directio write to random offsets to scatter CoW reservations.
10 # - Check the number of extents.
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1    # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23     cd /
24     rm -rf $tmp.*
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30 . ./common/reflink
31
32 # real QA test starts here
33 _supported_os Linux
34 _supported_fs xfs
35 _require_scratch_reflink
36 _require_cp_reflink
37 _require_xfs_io_command "fiemap"
38 _require_xfs_io_command "cowextsize"
39 _require_odirect
40
41 rm -f $seqres.full
42
43 echo "Format and mount"
44 _scratch_mkfs > $seqres.full 2>&1
45 _scratch_mount >> $seqres.full 2>&1
46
47 testdir=$SCRATCH_MNT/test-$seq
48 mkdir $testdir
49
50 blksz=65536
51 nr=128
52 filesize=$((blksz * nr))
53 bufnr=16
54 bufsize=$((blksz * bufnr))
55
56 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
57 real_blksz=$(_get_block_size $testdir)
58 internal_blks=$((filesize / real_blksz))
59
60 echo "Create the original files"
61 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $((filesize + 1))" $testdir/file1 >> $seqres.full
62 $XFS_IO_PROG -f -c "cowextsize $bufsize" $testdir/file2
63 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
64 _scratch_cycle_mount
65
66 echo "Compare files"
67 md5sum $testdir/file1 | _filter_scratch
68 md5sum $testdir/file2 | _filter_scratch
69
70 echo "CoW and unmount"
71 $XFS_IO_PROG -f -c "cowextsize" $testdir/file2 >> $seqres.full
72 $XFS_IO_PROG -d -f -c "pwrite -R -S 0x63 -b $real_blksz 0 $filesize" $testdir/file2 >> $seqres.full
73 _scratch_cycle_mount
74
75 echo "Compare files"
76 md5sum $testdir/file1 | _filter_scratch
77
78 echo "Check extent counts"
79 old_extents=$(_count_extents $testdir/file1)
80 new_extents=$(_count_extents $testdir/file2)
81
82 echo "old extents: $old_extents" >> $seqres.full
83 echo "new extents: $new_extents" >> $seqres.full
84 echo "maximum extents: $internal_blks" >> $seqres.full
85 test $new_extents -lt $((internal_blks * 2 / 3)) || echo "file2 badly fragmented"
86
87 # success, all done
88 status=0
89 exit