2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates. All Rights Reserved.
7 # Ensure that xfs_fsr handles quota correctly while defragging files.
10 _begin_fstest auto quick clone fsr quota
12 # Import common functions.
18 # real QA test starts here
20 _require_scratch_reflink
22 _require_xfs_io_command "falloc" # used in FSR
23 _require_command "$XFS_FSR_PROG" "xfs_fsr"
29 repquota $SCRATCH_MNT | egrep '^(fsgqa|root|nobody)' | sort -r
34 echo "Format and mount"
35 _scratch_mkfs > "$seqres.full" 2>&1
36 export MOUNT_OPTIONS="-o usrquota,grpquota $MOUNT_OPTIONS"
37 _scratch_mount >> "$seqres.full" 2>&1
38 quotacheck -u -g $SCRATCH_MNT 2> /dev/null
39 quotaon $SCRATCH_MNT 2> /dev/null
41 testdir="$SCRATCH_MNT/test-$seq"
46 echo "Create a many-block file"
48 chown nobody $testdir/file1
50 chown nobody $testdir/file2
51 _pwrite_byte 0x62 0 $((blksz * blks)) $testdir/file1 >> $seqres.full
52 _pwrite_byte 0x63 0 $blksz $testdir/file2 >> $seqres.full
53 _reflink_range $testdir/file2 0 $testdir/file1 $blksz $blksz >> $seqres.full
57 echo "Defrag the file"
58 old_nextents=$(_count_extents $testdir/file1)
59 $XFS_FSR_PROG -v -d $testdir/file1 >> $seqres.full
60 new_nextents=$(_count_extents $testdir/file1)
63 echo "Remount the FS to see if accounting changes"
67 echo "Check extent count"
68 $XFS_IO_PROG -c 'stat -v' $testdir/file1 >> $seqres.full
69 $XFS_IO_PROG -c 'stat -v' $testdir/file2 >> $seqres.full
70 echo "extents: $old_nextents -> $new_nextents" >> $seqres.full
71 test $old_nextents -gt $new_nextents || echo "FAIL: $old_nextents -> $new_nextents"