fsx/fsstress: round blocksize properly
[xfstests-dev.git] / tests / xfs / 508
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2019 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test 508
6 #
7 # Test project quota inheritance flag, uncover xfsprogs bug fixed by xfsprogs
8 # commit b136f48b19a5 ("xfs_quota: fix false error reporting of project
9 # inheritance flag is not set")
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 -f $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29 . ./common/quota
30
31 # remove previous $seqres.full before test
32 rm -f $seqres.full
33
34 # real QA test starts here
35 _supported_fs xfs
36 _require_scratch
37 _require_xfs_quota
38
39 cat >$tmp.projects <<EOF
40 10:$SCRATCH_MNT/dir
41 EOF
42
43 cat >$tmp.projid <<EOF
44 root:0
45 test:10
46 EOF
47
48 QUOTA_CMD="$XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid"
49
50 filter_xfs_pquota()
51 {
52         perl -ne "
53 s,$tmp.projects,[PROJECTS_FILE],;
54 s,$SCRATCH_MNT,[SCR_MNT],;
55 s,$SCRATCH_DEV,[SCR_DEV],;
56         print;"
57 }
58
59 do_quota_nospc()
60 {
61         local file=$1
62         local exp=$2
63
64         echo "Write $file, expect $exp:" | _filter_scratch
65         $XFS_IO_PROG -t -f -c "pwrite 0 5m" $file 2>&1 >/dev/null | \
66                 _filter_xfs_io_error
67         rm -f $file
68 }
69
70 _scratch_mkfs_xfs >>$seqres.full 2>&1
71 _qmount_option "prjquota"
72 _qmount
73 _require_prjquota $SCRATCH_DEV
74
75 mkdir $SCRATCH_MNT/dir
76 $QUOTA_CMD -x -c 'project -s test' $SCRATCH_MNT >>$seqres.full 2>&1
77 $QUOTA_CMD -x -c 'limit -p bsoft=1m bhard=2m test' $SCRATCH_MNT
78
79 # test the Project inheritance bit is a directory only flag, and it's set on
80 # directory by default. Expect no complain about "project inheritance flag is
81 # not set" on regular file.
82 echo "== The parent directory has Project inheritance bit by default =="
83 touch $SCRATCH_MNT/dir/foo
84 mkdir $SCRATCH_MNT/dir/dir_inherit
85 touch $SCRATCH_MNT/dir/dir_inherit/foo
86 $QUOTA_CMD -x -c 'project -c test' $SCRATCH_MNT | filter_xfs_pquota
87 echo ""
88
89 # test the quota and the project inheritance quota work well
90 do_quota_nospc $SCRATCH_MNT/dir/foo ENOSPC
91 do_quota_nospc $SCRATCH_MNT/dir/dir_inherit/foo ENOSPC
92 echo ""
93
94 # test the project quota won't be inherited, if removing the Project
95 # inheritance bit
96 echo "== After removing parent directory has Project inheritance bit =="
97 $XFS_IO_PROG -x -c "chattr -P" $SCRATCH_MNT/dir
98 touch $SCRATCH_MNT/dir/foo
99 mkdir $SCRATCH_MNT/dir/dir_uninherit
100 touch $SCRATCH_MNT/dir/dir_uninherit/foo
101 $QUOTA_CMD -x -c 'project -c test' $SCRATCH_MNT | filter_xfs_pquota
102 echo ""
103
104 # after remove the Project inheritance bit of the original parent directory,
105 # then verify:
106 # 1) there's not any limit on the original parent directory and files under it
107 # 2) the quota limit of sub-directory which has inherited still works
108 # 3) there's not limit on the new sub-dirctory (not inherit from parent)
109 do_quota_nospc $SCRATCH_MNT/dir/foo Success
110 do_quota_nospc $SCRATCH_MNT/dir/dir_inherit/foo ENOSPC
111 do_quota_nospc $SCRATCH_MNT/dir/dir_uninherit/foo Success
112
113 _scratch_unmount
114 # success, all done
115 status=0
116 exit