xfs: fix more xfs_db open-coding instances
[xfstests-dev.git] / tests / xfs / 244
1 #! /bin/bash
2 # FS QA Test No. 244
3 #
4 # test to verify that proper project quota id is correctly set
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2010 Arkadiusz Miƛkiewicz.  All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #
22 #-----------------------------------------------------------------------
23 #
24
25 seq=`basename $0`
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
28
29 here=`pwd`
30 tmp=/tmp/$$
31 status=1        # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
33
34 # get standard environment, filters and checks
35 . ./common/rc
36 . ./common/filter
37 . ./common/quota
38
39 _cleanup()
40 {
41         cd /
42         _scratch_unmount 2>/dev/null
43         rm -f $tmp.*
44 }
45
46 # real QA test starts here
47 _supported_fs xfs
48 _require_xfs_quota
49 _require_scratch
50 _require_projid32bit
51 _require_projid16bit
52
53 export MOUNT_OPTIONS="-opquota"
54
55 rm -f $seqres.full
56 # make fs with no projid32bit
57 _scratch_mkfs_xfs -i projid32bit=0 >> $seqres.full || _fail "mkfs failed"
58 _qmount
59 # make sure project quota is supported
60 _require_prjquota ${SCRATCH_DEV}
61
62 dir=$SCRATCH_MNT/project
63
64 status=0
65
66 echo "Silence is golden"
67
68 # Do testing on filesystem with projid32bit feature disabled
69 mkdir $dir
70
71 touch $dir/below16bit
72 # below 16bit value
73 $XFS_QUOTA_PROG -x -c "project -s -p $dir/below16bit 3422" $SCRATCH_DEV \
74                 >> $seqres.full
75 projid=$($XFS_IO_PROG -r -c "lsproj" $dir/below16bit)
76 if [ "projid = 3422" != "$projid" ]; then
77         echo "FAIL: projid32bit disabled: returned projid value ($projid)"
78         echo "      doesn't match set one (projid = 3422)"
79         status=1
80 fi
81
82 # 32bit value, should fail
83 touch $dir/over16bit
84 if $XFS_QUOTA_PROG -x -c "project -s -p $dir/over16bit 108545" $SCRATCH_DEV \
85                 >> $seqres.full 2>&1; then
86         echo "FAIL: projid32bit disabled: setting 32bit projid succeeded"
87         echo "      while it should fail"
88         status=1
89 fi
90
91 # over 32bit value, should fail
92 touch $dir/over32bit
93 if $XFS_QUOTA_PROG -x -c "project -s -p $dir/over32bit 5344967296" $SCRATCH_DEV >> $seqres.full 2>&1; then
94         echo "FAIL: projid32bit disabled: setting over 32bit projid succeeded"
95         echo "      while it should fail"
96         status=1
97 fi
98
99 #  Do testing on filesystem with projid32bit feature enabled
100 _scratch_unmount 2>/dev/null
101 _scratch_mkfs_xfs -i projid32bit=1 >> $seqres.full || _fail "mkfs failed"
102 _qmount
103 mkdir $dir
104
105 touch $dir/below16bit
106 # below 16bit value, should succeed
107 $XFS_QUOTA_PROG -x -c "project -s -p $dir/below16bit 3422" $SCRATCH_DEV \
108                 >> $seqres.full
109 projid=$($XFS_IO_PROG -r -c "lsproj" $dir/below16bit)
110 if [ "projid = 3422" != "$projid" ]; then
111         echo "FAIL: projid32bit enabled: returned projid value ($projid)"
112         echo "      doesn't match set one (projid = 3422)"
113         status=1
114 fi
115
116 # 32bit value, should succeed
117 touch $dir/over16bit
118 if $XFS_QUOTA_PROG -x -c "project -s -p $dir/over16bit 108545" $SCRATCH_DEV \
119                 >> $seqres.full 2>&1; then
120         projid=$($XFS_IO_PROG -r -c "lsproj" $dir/over16bit)
121         if [ "projid = 108545" != "$projid" ]; then
122                 echo "FAIL: projid32bit enabled: returned projid value ($projid)"
123                 echo "      doesn't match set one (projid = 108545)"
124                 status=1
125         fi
126 else
127         echo "FAIL: projid32bit enabled: setting 32bit projid failed"
128         echo "      while it should succeed"
129         status=1
130 fi
131
132 # over 32bit value, should fail
133 touch $dir/over32bit
134 if $XFS_QUOTA_PROG -x -c "project -s -p $dir/over32bit 5344967296" $SCRATCH_DEV \
135                 >> $seqres.full 2>&1; then
136         echo "FAIL: projid32bit enabled: setting over 32bit projid succeeded"
137         echo "      while it should fail"
138         status=1
139 fi