xfs: force file creation to the data device for certain layout tests
[xfstests-dev.git] / tests / xfs / 213
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. 213
6 #
7 # Ensure that quota charges us for reflnking a file and that we're not
8 # charged for buffered copy on write.  Same test as g/305, but we get to
9 # play with cowextsz.
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 here=`pwd`
16 tmp=/tmp/$$
17 status=1    # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
19
20 _cleanup()
21 {
22     cd /
23     rm -rf $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29 . ./common/reflink
30 . ./common/quota
31
32 # real QA test starts here
33 _supported_fs xfs
34 _require_scratch_reflink
35 _require_cp_reflink
36 _require_xfs_io_command "fiemap"
37 _require_quota
38 _require_nobody
39 _require_xfs_io_command "cowextsize"
40 _require_user
41
42 rm -f $seqres.full
43
44 echo "Format and mount"
45 _scratch_mkfs > $seqres.full 2>&1
46 export MOUNT_OPTIONS="-o usrquota,grpquota $MOUNT_OPTIONS"
47 _scratch_mount >> $seqres.full 2>&1
48 quotacheck -u -g $SCRATCH_MNT 2> /dev/null
49 quotaon $SCRATCH_MNT 2> /dev/null
50
51 testdir=$SCRATCH_MNT/test-$seq
52 mkdir $testdir
53
54 sz=1048576
55 blksz=65536
56 echo "Create the original files"
57 $XFS_IO_PROG -c "cowextsize $((sz/2))" $testdir >> $seqres.full
58 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $sz 0 $sz" $testdir/file1 >> $seqres.full
59 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
60 _cp_reflink $testdir/file1 $testdir/file3 >> $seqres.full
61 touch $testdir/urk
62 chown nobody $testdir/urk
63 touch $testdir/erk
64 chown $qa_user $testdir/erk
65 _report_quota_blocks $SCRATCH_MNT
66 _scratch_cycle_mount
67
68 echo "Change file ownership"
69 chown $qa_user $testdir/file1
70 chown $qa_user $testdir/file2
71 chown $qa_user $testdir/file3
72 _report_quota_blocks $SCRATCH_MNT
73
74 echo "CoW one of the files"
75 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $blksz $((sz - blksz)) $blksz" -c "fsync" $testdir/file2 >> $seqres.full
76 _report_quota_blocks $SCRATCH_MNT
77
78 echo "Remount the FS to see if accounting changes"
79 _scratch_cycle_mount
80 _report_quota_blocks $SCRATCH_MNT
81
82 echo "Chown one of the files"
83 chown nobody $testdir/file3
84 _report_quota_blocks $SCRATCH_MNT
85
86 # success, all done
87 status=0
88 exit