generic: test for non-zero used blocks while writing into a file
[xfstests-dev.git] / tests / generic / 302
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. 302
6 #
7 # Test fragmentation after a lot of random CoW:
8 # - Create two reflinked files.
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 _require_scratch_reflink
34 _require_cp_reflink
35 _require_xfs_io_command "fiemap"
36 _require_odirect
37
38 rm -f $seqres.full
39
40 echo "Format and mount"
41 _scratch_mkfs > $seqres.full 2>&1
42 _scratch_mount >> $seqres.full 2>&1
43
44 testdir=$SCRATCH_MNT/test-$seq
45 mkdir $testdir
46
47 blksz=65536
48 nr=128
49 filesize=$((blksz * nr))
50 bufnr=16
51 bufsize=$((blksz * bufnr))
52
53 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
54 real_blksz=$(_get_block_size $testdir)
55 internal_blks=$((filesize / real_blksz))
56
57 echo "Create the original files"
58 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $((filesize + 1))" $testdir/file1 >> $seqres.full
59 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
60 _scratch_cycle_mount
61
62 echo "Compare files"
63 md5sum $testdir/file1 | _filter_scratch
64 md5sum $testdir/file2 | _filter_scratch
65
66 echo "CoW and unmount"
67 for i in `seq 1 8`; do
68         $XFS_IO_PROG -d -f -c "pwrite -R -S 0x63 -b $real_blksz 0 $filesize" $testdir/file2 >> $seqres.full
69 done
70 _scratch_cycle_mount
71
72 echo "Compare files"
73 md5sum $testdir/file1 | _filter_scratch
74
75 echo "Check extent counts"
76 old_extents=$(_count_extents $testdir/file1)
77 new_extents=$(_count_extents $testdir/file2)
78
79 echo "old extents: $old_extents" >> $seqres.full
80 echo "new extents: $new_extents" >> $seqres.full
81 echo "maximum extents: $internal_blks" >> $seqres.full
82 test $new_extents -le $internal_blks || echo "file2 badly fragmented"
83
84 # success, all done
85 status=0
86 exit