xfs/029: filter out "extended-header: cycle: 1" from output
[xfstests-dev.git] / tests / xfs / 330
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. 330
6 #
7 # Ensure that xfs_fsr handles quota correctly while defragging files.
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 -rf "$tmp".*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27 . ./common/attr
28 . ./common/reflink
29 . ./common/quota
30
31 # real QA test starts here
32 _supported_os Linux
33 _supported_fs xfs
34 _require_scratch_reflink
35 _require_cp_reflink
36 _require_xfs_io_command "falloc" # used in FSR
37 _require_command "$XFS_FSR_PROG" "xfs_fsr"
38 _require_quota
39 _require_nobody
40
41 do_repquota()
42 {
43         repquota $SCRATCH_MNT | egrep '^(fsgqa|root|nobody)' | sort -r
44 }
45
46 rm -f "$seqres.full"
47
48 echo "Format and mount"
49 _scratch_mkfs > "$seqres.full" 2>&1
50 export MOUNT_OPTIONS="-o usrquota,grpquota $MOUNT_OPTIONS"
51 _scratch_mount >> "$seqres.full" 2>&1
52 quotacheck -u -g $SCRATCH_MNT 2> /dev/null
53 quotaon $SCRATCH_MNT 2> /dev/null
54
55 testdir="$SCRATCH_MNT/test-$seq"
56 blksz=65536
57 blks=3
58 mkdir "$testdir"
59
60 echo "Create a many-block file"
61 touch $testdir/file1
62 chown nobody $testdir/file1
63 touch $testdir/file2
64 chown nobody $testdir/file2
65 _pwrite_byte 0x62 0 $((blksz * blks)) $testdir/file1 >> $seqres.full
66 _pwrite_byte 0x63 0 $blksz $testdir/file2 >> $seqres.full
67 _reflink_range $testdir/file2 0 $testdir/file1 $blksz $blksz >> $seqres.full
68 do_repquota
69 _scratch_cycle_mount
70
71 echo "Defrag the file"
72 old_nextents=$(_count_extents $testdir/file1)
73 $XFS_FSR_PROG -v -d $testdir/file1 >> $seqres.full
74 new_nextents=$(_count_extents $testdir/file1)
75 do_repquota
76
77 echo "Remount the FS to see if accounting changes"
78 _scratch_cycle_mount
79 do_repquota
80
81 echo "Check extent count"
82 $XFS_IO_PROG -c 'stat -v' $testdir/file1 >> $seqres.full
83 $XFS_IO_PROG -c 'stat -v' $testdir/file2 >> $seqres.full
84 echo "extents: $old_nextents -> $new_nextents" >> $seqres.full
85 test $old_nextents -gt $new_nextents || echo "FAIL: $old_nextents -> $new_nextents"
86
87 # success, all done
88 status=0
89 exit