generic: test for non-zero used blocks while writing into a file
[xfstests-dev.git] / tests / generic / 382
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test 382
6 #
7 # When default quota is set, all different quota types inherits the
8 # same default value, include group quota. So if a user quota limit
9 # larger than the default user quota value, it will still be limited
10 # by the group default quota value.
11 #
12 # There's a patch from Upstream can fix this bug:
13 #
14 #    [PATCH] xfs: Split default quota limits by quota type V4
15 #
16 seq=`basename $0`
17 seqres=$RESULT_DIR/$seq
18 echo "QA output created by $seq"
19
20 here=`pwd`
21 tmp=/tmp/$$
22 status=1        # failure is the default!
23 trap "_cleanup; exit \$status" 0 1 2 3 15
24
25 _cleanup()
26 {
27         cd /
28         rm -f $tmp.*
29 }
30
31 # get standard environment, filters and checks
32 . ./common/rc
33 . ./common/filter
34 . ./common/quota
35
36 # remove previous $seqres.full before test
37 rm -f $seqres.full
38
39 # real QA test starts here
40 _supported_fs generic
41 _require_scratch
42 _require_quota
43 _require_xfs_quota_foreign
44 _require_user
45 _require_group
46
47 do_test()
48 {
49         local qname=$1
50         local type
51
52         if [ "$qname" = "user" ];then
53                 type="-u"
54                 echo "=== user quota test ==="
55         elif [ "$qname" = "group" ];then
56                 type="-g"
57                 echo "=== group quota test ==="
58         else
59                 echo "wrong quota type name - $qname"
60                 return 1
61         fi
62
63         $XFS_QUOTA_PROG -x -c "limit bsoft=20M bhard=20M isoft=20 ihard=20 $type -d" $SCRATCH_MNT
64         $XFS_QUOTA_PROG -x -c "limit bsoft=40M bhard=40M isoft=40 ihard=40 $type fsgqa" $SCRATCH_MNT
65         echo "$qname blocks and inode limit"
66         $XFS_QUOTA_PROG -x -c "report $type -N -bi" $SCRATCH_MNT | grep -v ^root | _filter_spaces
67
68         ## blocks default quota test ##
69         _user_do "$XFS_IO_PROG -f -c \"pwrite 0 30M\" -c \"fsync\" $SCRATCH_MNT/data" | _filter_xfs_io
70
71         rm -f ${SCRATCH_MNT}/* >/dev/null 2>&1
72
73         ## inode default quota test ##
74         for ((i=0; i<30; i++));do
75                 _user_do "echo -n > ${SCRATCH_MNT}/file${i}"
76         done
77         sync
78
79         rm -f ${SCRATCH_MNT}/* >/dev/null 2>&1
80 }
81
82 ### user default quota test ###
83 _scratch_mkfs >/dev/null 2>&1
84 _qmount_option "usrquota,grpquota"
85 _qmount
86
87 do_test user
88
89 ### group default quota test ###
90 _scratch_unmount
91 _scratch_mkfs >/dev/null 2>&1
92 _qmount_option "grpquota,usrquota"
93 _qmount
94
95 do_test group
96
97 # success, all done
98 status=0
99 exit