fstests: check for filesystem FS_IOC_FSSETXATTR support
[xfstests-dev.git] / tests / xfs / 128
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 128
6 #
7 # Ensure that xfs_fsr un-reflinks files while defragmenting
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/reflink
28
29 # real QA test starts here
30 _supported_os Linux
31 _supported_fs xfs
32 _require_test_lsattr
33 _require_scratch_reflink
34 _require_cp_reflink
35 _require_xfs_io_command "falloc"
36
37 echo "Format and mount"
38 _scratch_mkfs > $seqres.full 2>&1
39 _scratch_mount >> $seqres.full 2>&1
40
41 testdir=$SCRATCH_MNT/test-$seq
42 mkdir $testdir
43 free_blocks0=$(stat -f $testdir -c '%f')
44
45 echo "Create the original file and reflink to file2, file3"
46 blks=2000
47 margin=160
48 blksz=65536
49 real_blksz="$(_get_block_size $testdir)"
50 blksz_factor=$((blksz / real_blksz))
51 _pwrite_byte 0x61 0 $((blks * blksz)) $testdir/file1 >> $seqres.full
52 _cp_reflink $testdir/file1 $testdir/file2
53 _cp_reflink $testdir/file2 $testdir/file3
54 _cp_reflink $testdir/file3 $testdir/file4
55 _scratch_cycle_mount
56 free_blocks1=$(stat -f $testdir -c '%f')
57
58 md5sum $testdir/file1 | _filter_scratch
59 md5sum $testdir/file2 | _filter_scratch
60 md5sum $testdir/file3 | _filter_scratch
61 md5sum $testdir/file4 | _filter_scratch
62
63 c01=$(_md5_checksum $testdir/file1)
64 c02=$(_md5_checksum $testdir/file2)
65 c03=$(_md5_checksum $testdir/file3)
66 c04=$(_md5_checksum $testdir/file4)
67
68 echo "CoW the reflink copies"
69 _pwrite_byte 0x62 $blksz $blksz $testdir/file2 >> $seqres.full
70 _pwrite_byte 0x63 $(( blksz * (blks - 1) )) $blksz $testdir/file3 >> $seqres.full
71 _scratch_cycle_mount
72 free_blocks2=$(stat -f $testdir -c '%f')
73
74 md5sum $testdir/file1 | _filter_scratch
75 md5sum $testdir/file2 | _filter_scratch
76 md5sum $testdir/file3 | _filter_scratch
77 md5sum $testdir/file4 | _filter_scratch
78
79 c11=$(_md5_checksum $testdir/file1)
80 c12=$(_md5_checksum $testdir/file2)
81 c13=$(_md5_checksum $testdir/file3)
82 c14=$(_md5_checksum $testdir/file4)
83
84 echo "Defragment"
85 lsattr -l $testdir/ | _filter_scratch | _filter_spaces
86 $XFS_FSR_PROG -v -d $testdir/file1 >> $seqres.full
87 $XFS_FSR_PROG -v -d $testdir/file2 >> $seqres.full # fsr probably breaks the link
88 $XFS_FSR_PROG -v -d $testdir/file3 >> $seqres.full # fsr probably breaks the link
89 $XFS_FSR_PROG -v -d $testdir/file4 >> $seqres.full # fsr probably ignores this file
90 _scratch_cycle_mount
91 free_blocks3=$(stat -f $testdir -c '%f')
92
93 md5sum $testdir/file1 | _filter_scratch
94 md5sum $testdir/file2 | _filter_scratch
95 md5sum $testdir/file3 | _filter_scratch
96 md5sum $testdir/file4 | _filter_scratch
97
98 c21=$(_md5_checksum $testdir/file1)
99 c22=$(_md5_checksum $testdir/file2)
100 c23=$(_md5_checksum $testdir/file3)
101 c24=$(_md5_checksum $testdir/file4)
102
103 echo "Check files"
104 test $c01 = $c02 || echo "Files 1-2 do not match"
105 test $c01 = $c03 || echo "Files 1-3 do not match"
106 test $c01 = $c04 || echo "Files 1-4 do not match"
107 test $c02 = $c03 || echo "Files 2-3 do not match"
108 test $c02 = $c04 || echo "Files 2-4 do not match"
109 test $c03 = $c04 || echo "Files 3-4 do not match"
110
111 test $c01 = $c11 || echo "File1 should not be different after CoW"
112 test $c02 != $c12 || echo "File2 should be different after CoW"
113 test $c03 != $c13 || echo "File3 should be different after CoW"
114 test $c04 = $c14 || echo "File4 should not be different after CoW"
115
116 test $c11 = $c21 || echo "File1 changed by defrag"
117 test $c12 = $c22 || echo "File2 changed by defrag"
118 test $c13 = $c23 || echo "File3 changed by defrag"
119 test $c14 = $c24 || echo "File4 changed by defrag"
120
121 #echo $free_blocks0 $free_blocks1 $free_blocks2 $free_blocks3
122
123 _within_tolerance "free blocks after creating some reflink copies" $free_blocks1 $((free_blocks0 - (blks * blksz_factor) )) $margin -v
124 _within_tolerance "free blocks after CoW some reflink copies" $free_blocks2 $((free_blocks1 - 2)) $margin -v
125 _within_tolerance "free blocks after defragging all reflink copies" $free_blocks3 $((free_blocks2 - (blks * 2 * blksz_factor))) $margin -v
126 _within_tolerance "free blocks after all tests" $free_blocks3 $((free_blocks0 - (blks * 3 * blksz_factor))) $margin -v
127
128 # success, all done
129 status=0
130 exit