xfstests: introduce a common directory
[xfstests-dev.git] / tests / xfs / 107
1 #! /bin/bash
2 # FS QA Test No. 107
3 #
4 # Project quota.
5 # Use of "sync" mount option here is an attempt to get deterministic
6 # allocator behaviour.
7 #
8 #-----------------------------------------------------------------------
9 # Copyright (c) 2005 Silicon Graphics, Inc.  All Rights Reserved.
10 #
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License as
13 # published by the Free Software Foundation.
14 #
15 # This program is distributed in the hope that it would be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write the Free Software Foundation,
22 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23 #
24 #-----------------------------------------------------------------------
25 #
26
27 seq=`basename $0`
28 seqres=$RESULT_DIR/$seq
29 seqres=$RESULT_DIR/$seq
30 seqres=$RESULT_DIR/$seq
31 echo "QA output created by $seq"
32
33 here=`pwd`
34 tmp=/tmp/$$
35 status=1        # failure is the default!
36 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
37
38 # get standard environment, filters and checks
39 . ./common/rc
40 . ./common/filter
41 . ./common/quota
42
43 filter_xfs_quota()
44 {
45         perl -ne "
46 s,$target,[TARGET],;
47 s,$tmp.projects,[PROJECTS_FILE],;
48 s,$SCRATCH_MNT,[SCR_MNT],;
49 s,$SCRATCH_DEV,[SCR_DEV],;
50 s/Inode: \#\d+ \(0 blocks, 0 extents\)/Inode: #[INO] (0 blocks, 0 extents)/;
51 s/Inode: \#\d+ \(\d+ blocks, \d+ extents\)/Inode: #[INO] (X blocks, Y extents)/;
52         print;"
53 }
54
55 _supported_fs xfs
56 _supported_os Linux #IRIX
57 _require_scratch
58 _require_xfs_quota
59
60 # real QA test starts here
61 _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
62 cat $tmp.mkfs >$seqres.full
63 . $tmp.mkfs
64
65 # setup a default run
66 if [ -z "$MOUNT_OPTIONS" ]; then
67         export MOUNT_OPTIONS="-o pquota,sync"
68 else
69         export MOUNT_OPTIONS="$MOUNT_OPTIONS -o sync"
70 fi
71
72 _qmount
73 _require_prjquota $SCRATCH_DEV
74
75 echo "### create projects file"
76 rm -f $tmp.projects
77 target=$SCRATCH_MNT/project
78 echo "6:$target" | tee -a $seqres.full > $tmp.projects
79
80 echo "### populate filesystem"
81 mkdir $target           || exit
82 $FSSTRESS_PROG -z -s 65261 -m 8 -n 1000 -p 4 \
83 -f allocsp=1 \
84 -f chown=3 \
85 -f creat=4 \
86 -f dwrite=4 \
87 -f fallocate=1 \
88 -f fdatasync=1 \
89 -f fiemap=1 \
90 -f freesp=1 \
91 -f fsync=1 \
92 -f link=1 \
93 -f mkdir=2 \
94 -f punch=1 \
95 -f rename=2 \
96 -f resvsp=1 \
97 -f rmdir=1 \
98 -f setxattr=1 \
99 -f sync=1 \
100 -f truncate=2 \
101 -f unlink=1 \
102 -f unresvsp=1 \
103 -f write=4 \
104 -d $target
105
106 $FSSTRESS_PROG -z -s 47806 -m 8 -n 500 -p 4 \
107 -f chown=250 \
108 -f setxattr=250 \
109 -d $target
110
111
112 QARGS="-x -D $tmp.projects -P /dev/null $SCRATCH_MNT"
113
114 echo "### initial report"
115 xfs_quota -c 'quot -p' -c 'quota -ip 6' $QARGS | filter_xfs_quota
116
117 echo "### check the project, should give warnings"
118 xfs_quota -c 'project -c 6' $QARGS | LC_COLLATE=POSIX sort | filter_xfs_quota
119
120 echo "### recursively setup the project"
121 xfs_quota -c 'project -s 6' $QARGS | LC_COLLATE=POSIX sort | filter_xfs_quota
122 xfs_quota -c 'quota -ip 6' $QARGS | filter_xfs_quota
123
124 echo "### check the project, should give no warnings now"
125 xfs_quota -c 'project -c 6' $QARGS | LC_COLLATE=POSIX sort | filter_xfs_quota
126
127 echo "### deny a hard link - wrong project ID"
128 rm -f $SCRATCH_MNT/outer $target/inner
129 $XFS_IO_PROG -f -c 'chproj 789' $SCRATCH_MNT/outer
130 ln $SCRATCH_MNT/outer $target/inner 2>/dev/null
131 if [ $? -eq 0 ]; then
132         echo hard link succeeded
133         ls -ld $SCRATCH_MNT/outer $target/inner
134 else
135         echo hard link failed
136 fi
137 xfs_quota -c 'quota -ip 6' $QARGS | filter_xfs_quota
138
139 echo "### allow a hard link - right project ID"
140 $XFS_IO_PROG -c 'chproj 6' $SCRATCH_MNT/outer
141 ln $SCRATCH_MNT/outer $target/inner
142 if [ $? -eq 0 ]; then
143         echo hard link succeeded
144 else
145         echo hard link failed
146         ls -ld $SCRATCH_MNT/outer $target/inner
147 fi
148 xfs_quota -c 'quota -ip 6' $QARGS | filter_xfs_quota
149
150 echo "### recursively clear the project"
151 xfs_quota -c 'project -C 6' $QARGS | LC_COLLATE=POSIX sort | filter_xfs_quota
152 #no output...
153 xfs_quota -c 'quota -ip 6' $QARGS | filter_xfs_quota
154
155 status=0
156 exit