lib/: spdx license conversion
[xfstests-dev.git] / tests / generic / 328
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. 328
6 #
7 # Ensure that we can't go over the hard block limit when CoWing a file.
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/reflink
28 . ./common/quota
29
30 # real QA test starts here
31 _supported_os Linux
32 _require_scratch_reflink
33 _require_cp_reflink
34 _require_xfs_io_command "fiemap"
35 _require_quota
36 _require_nobody
37 _require_odirect
38 _require_user
39
40 rm -f $seqres.full
41
42 echo "Format and mount"
43 _scratch_mkfs > $seqres.full 2>&1
44 export MOUNT_OPTIONS="-o usrquota,grpquota $MOUNT_OPTIONS"
45 _scratch_mount >> $seqres.full 2>&1
46 quotacheck -u -g $SCRATCH_MNT 2> /dev/null
47 quotaon $SCRATCH_MNT 2> /dev/null
48
49 testdir=$SCRATCH_MNT/test-$seq
50 mkdir $testdir
51
52 sz=1048576
53 echo "Create the original files"
54 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $sz 0 $sz" $testdir/file1 >> $seqres.full
55 chown $qa_user $testdir/file1
56 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
57 _cp_reflink $testdir/file1 $testdir/file3 >> $seqres.full
58 _report_quota_blocks $SCRATCH_MNT
59 _scratch_cycle_mount
60 quotaon $SCRATCH_MNT 2> /dev/null
61
62 echo "Set hard quota to prevent rewrite"
63 setquota -u $qa_user 0 1024 0 0 $SCRATCH_MNT
64 _report_quota_blocks $SCRATCH_MNT
65
66 echo "Try to dio write the whole file"
67 su $qa_user -c '$XFS_IO_PROG -d -c "pwrite 0 '$((sz+65536))'" '$testdir'/file1' 2>&1 >> $seqres.full | \
68         _filter_xfs_io_error
69 _report_quota_blocks $SCRATCH_MNT
70
71 echo "Try to write the whole file"
72 su $qa_user -c '$XFS_IO_PROG -c "pwrite 0 '$((sz+65536))'" '$testdir'/file1' 2>&1 >> $seqres.full | \
73         _filter_xfs_io_error
74 _report_quota_blocks $SCRATCH_MNT
75
76 echo "Set hard quota to allow rewrite"
77 setquota -u $qa_user 0 8192 0 0 $SCRATCH_MNT
78 _report_quota_blocks $SCRATCH_MNT
79
80 echo "Try to dio write the whole file"
81 _pwrite_byte 0x62 0 $sz $testdir/file1 -d >> $seqres.full
82 sync
83 _report_quota_blocks $SCRATCH_MNT
84
85 echo "Try to write the whole file"
86 _pwrite_byte 0x62 0 $sz $testdir/file3 >> $seqres.full
87 sync
88 _report_quota_blocks $SCRATCH_MNT
89
90 # success, all done
91 status=0
92 exit