fstests: move test group info to test files
[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 . ./common/preamble
12 _begin_fstest auto quick quota
13
14 # Import common functions.
15 . ./common/filter
16 . ./common/quota
17
18 # real QA test starts here
19 _supported_fs xfs
20 _require_scratch
21 _require_xfs_quota
22
23 cat >$tmp.projects <<EOF
24 10:$SCRATCH_MNT/dir
25 EOF
26
27 cat >$tmp.projid <<EOF
28 root:0
29 test:10
30 EOF
31
32 QUOTA_CMD="$XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid"
33
34 filter_xfs_pquota()
35 {
36         perl -ne "
37 s,$tmp.projects,[PROJECTS_FILE],;
38 s,$SCRATCH_MNT,[SCR_MNT],;
39 s,$SCRATCH_DEV,[SCR_DEV],;
40         print;"
41 }
42
43 do_quota_nospc()
44 {
45         local file=$1
46         local exp=$2
47
48         echo "Write $file, expect $exp:" | _filter_scratch
49         $XFS_IO_PROG -t -f -c "pwrite 0 5m" $file 2>&1 >/dev/null | \
50                 _filter_xfs_io_error
51         rm -f $file
52 }
53
54 _scratch_mkfs_xfs >>$seqres.full 2>&1
55 _qmount_option "prjquota"
56 _qmount
57 _require_prjquota $SCRATCH_DEV
58
59 mkdir $SCRATCH_MNT/dir
60 $QUOTA_CMD -x -c 'project -s test' $SCRATCH_MNT >>$seqres.full 2>&1
61 $QUOTA_CMD -x -c 'limit -p bsoft=1m bhard=2m test' $SCRATCH_MNT
62
63 # test the Project inheritance bit is a directory only flag, and it's set on
64 # directory by default. Expect no complain about "project inheritance flag is
65 # not set" on regular file.
66 echo "== The parent directory has Project inheritance bit by default =="
67 touch $SCRATCH_MNT/dir/foo
68 mkdir $SCRATCH_MNT/dir/dir_inherit
69 touch $SCRATCH_MNT/dir/dir_inherit/foo
70 $QUOTA_CMD -x -c 'project -c test' $SCRATCH_MNT | filter_xfs_pquota
71 echo ""
72
73 # test the quota and the project inheritance quota work well
74 do_quota_nospc $SCRATCH_MNT/dir/foo ENOSPC
75 do_quota_nospc $SCRATCH_MNT/dir/dir_inherit/foo ENOSPC
76 echo ""
77
78 # test the project quota won't be inherited, if removing the Project
79 # inheritance bit
80 echo "== After removing parent directory has Project inheritance bit =="
81 $XFS_IO_PROG -x -c "chattr -P" $SCRATCH_MNT/dir
82 touch $SCRATCH_MNT/dir/foo
83 mkdir $SCRATCH_MNT/dir/dir_uninherit
84 touch $SCRATCH_MNT/dir/dir_uninherit/foo
85 $QUOTA_CMD -x -c 'project -c test' $SCRATCH_MNT | filter_xfs_pquota
86 echo ""
87
88 # after remove the Project inheritance bit of the original parent directory,
89 # then verify:
90 # 1) there's not any limit on the original parent directory and files under it
91 # 2) the quota limit of sub-directory which has inherited still works
92 # 3) there's not limit on the new sub-dirctory (not inherit from parent)
93 do_quota_nospc $SCRATCH_MNT/dir/foo Success
94 do_quota_nospc $SCRATCH_MNT/dir/dir_inherit/foo ENOSPC
95 do_quota_nospc $SCRATCH_MNT/dir/dir_uninherit/foo Success
96
97 _scratch_unmount
98 # success, all done
99 status=0
100 exit