common/filter: refactor quota report filtering
[xfstests-dev.git] / tests / xfs / 050
index 92e3d4c432b0e93a87973c3a2b87f238e8ae8793..1df975379922a5e3c92718aed4f5a2e59005f8f6 100755 (executable)
@@ -1,32 +1,14 @@
 #! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
+#
 # FS QA Test No. 050
 #
 # Exercises basic XFS quota functionality
 #       uquota, gquota, uqnoenforce, gqnoenforce, pquota, pqnoenforce
 #
-#-----------------------------------------------------------------------
-# Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write the Free Software Foundation,
-# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-#
-#-----------------------------------------------------------------------
-#
-
 seq=`basename $0`
 seqres=$RESULT_DIR/$seq
-seqres=$RESULT_DIR/$seq
-seqres=$RESULT_DIR/$seq
 echo "QA output created by $seq"
 
 here=`pwd`
@@ -41,16 +23,13 @@ status=1    # failure is the default!
 _cleanup()
 {
        cd /
-       umount $SCRATCH_MNT 2>/dev/null
+       _scratch_unmount 2>/dev/null
        rm -f $tmp.*
 }
 trap "_cleanup; exit \$status" 0 1 2 3 15
 
-
 # real QA test starts here
 _supported_fs xfs
-_supported_os Linux IRIX
-
 
 cp /dev/null $seqres.full
 chmod a+rwx $seqres.full       # arbitrary users will write here
@@ -58,27 +37,16 @@ chmod a+rwx $seqres.full    # arbitrary users will write here
 _require_scratch
 _require_xfs_quota
 
-bsoft=100
-bhard=500
+_scratch_mkfs >/dev/null 2>&1
+_scratch_mount
+bsize=$(_get_file_block_size $SCRATCH_MNT)
+_scratch_unmount
+
+bsoft=$(( 200 * $bsize ))
+bhard=$(( 1000 * $bsize ))
 isoft=4
 ihard=10
 
-
-_filter_report()
-{
-       tr -s '[:space:]' | \
-       perl -npe '
-               s/^\#'$id' /[NAME] /g;
-               s/^\#0 \d+ /[ROOT] 0 /g;
-               s/6 days/7 days/g' |
-       perl -npe '
-               $val = 0;
-               if ($ENV{'LARGE_SCRATCH_DEV'}) {
-                       $val = $ENV{'NUM_SPACE_FILES'};
-               }
-               s/(^\[ROOT\] \S+ \S+ \S+ \S+ \[--------\] )(\S+)/$1@{[$2 - $val]}/g'
-}
-
 # The actual point at which limit enforcement takes place for the
 # hard block limit is variable depending on filesystem blocksize,
 # and iosize.  What we want to test is that the limit is enforced
@@ -91,13 +59,33 @@ _filter_and_check_blks()
                if (/^\#'$id'\s+(\d+)/ && '$enforce') {
                        $maximum = '$bhard';
                        $minimum = '$bhard' * 85/100;
-                       if (($1 < $minimum || $1 > $maximum) && '$noextsz') {
+                       $used = $1 * 1024;
+                       if (($used < $minimum || $used > $maximum) && '$noextsz') {
                                printf(" URK %d: %d is out of range! [%d,%d]\n",
-                                       '$id', $1, $minimum, $maximum);
+                                       '$id', $used, $minimum, $maximum);
                        }
                        s/^(\#'$id'\s+)(\d+)/\1 =OK=/g;
                }
-       ' | _filter_report
+       ' | _filter_quota_report
+}
+
+_qsetup()
+{
+       opt=$1
+       enforce=0
+       if [ $opt = "u" -o $opt = "uno" ]; then
+               type=u
+               eval `_choose_uid`
+       elif [ $opt = "g" -o $opt = "gno" ]; then
+               type=g
+               eval `_choose_gid`
+       elif [ $opt = "p" -o $opt = "pno" ]; then
+               type=p
+               eval `_choose_prid`
+       fi
+       [ $opt = "u" -o $opt = "g" -o $opt = "p" ] && enforce=1
+
+       echo "Using type=$type id=$id" >> $seqres.full
 }
 
 _exercise()
@@ -118,46 +106,52 @@ _exercise()
        [ $extsize -ge 512000 ] && \
                _notrun "Extent size hint is too large ($extsize bytes)"
 
-       _qsetup
+       _qsetup $1
+
+       echo "Using type=$type id=$id" >>$seqres.full
 
-       echo "Using output from '" `ls -l $seq.out` "'" >>$seqres.full
-       echo "and using type=$type id=$id" >>$seqres.full
+       $XFS_QUOTA_PROG -x -c "warn -$type 65535 -d" $SCRATCH_DEV
 
        echo
        echo "*** report no quota settings" | tee -a $seqres.full
-       xfs_quota -D $tmp.projects -P $tmp.projid -x \
+       $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
                -c "repquota -birnN -$type" $SCRATCH_DEV |
-               _filter_report | LC_COLLATE=POSIX sort -ru
+               _filter_quota_report | LC_COLLATE=POSIX sort -ru
 
        echo
        echo "*** report initial settings" | tee -a $seqres.full
        _file_as_id $SCRATCH_MNT/initme $id $type 1024 0
        echo "ls -l $SCRATCH_MNT" >>$seqres.full
        ls -l $SCRATCH_MNT >>$seqres.full
-       xfs_quota -D $tmp.projects -P $temp.projid -x \
-               -c "limit -$type bsoft=${bsoft}k bhard=${bhard}k $id" \
+       $XFS_QUOTA_PROG -D $tmp.projects -P $temp.projid -x \
+               -c "limit -$type bsoft=${bsoft} bhard=${bhard} $id" \
                -c "limit -$type isoft=$isoft ihard=$ihard $id" \
                $SCRATCH_DEV
-       xfs_quota -D $tmp.projects -P $tmp.projid -x \
+       $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
                -c "repquota -birnN -$type" $SCRATCH_DEV |
-               _filter_report | LC_COLLATE=POSIX sort -ru
+               _filter_quota_report | LC_COLLATE=POSIX sort -ru
 
        echo
        echo "*** push past the soft inode limit" | tee -a $seqres.full
        _file_as_id $SCRATCH_MNT/softie1 $id $type 1024 0
        _file_as_id $SCRATCH_MNT/softie2 $id $type 1024 0
+       _file_as_id $SCRATCH_MNT/softie3 $id $type 1024 0
+       _file_as_id $SCRATCH_MNT/softie4 $id $type 1024 0
        _qmount
-       xfs_quota -D $tmp.projects -P $tmp.projid -x \
+       $XFS_QUOTA_PROG -x -c "warn -i -$type 0 $id" $SCRATCH_DEV
+       $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
                -c "repquota -birnN -$type" $SCRATCH_DEV |
-               _filter_report | LC_COLLATE=POSIX sort -ru
+               _filter_quota_report | LC_COLLATE=POSIX sort -ru
 
        echo
        echo "*** push past the soft block limit" | tee -a $seqres.full
-       _file_as_id $SCRATCH_MNT/softie $id $type 1024 140
+       _file_as_id $SCRATCH_MNT/softie $id $type $bsize 300
        _qmount
-       xfs_quota -D $tmp.projects -P $tmp.projid -x \
+       $XFS_QUOTA_PROG -x -c "warn -i -$type 0 $id" \
+               -c "warn -b -$type 0 $id" $SCRATCH_DEV
+       $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
                -c "repquota -birnN -$type" $SCRATCH_DEV |
-               _filter_report | LC_COLLATE=POSIX sort -ru
+               _filter_quota_report | LC_COLLATE=POSIX sort -ru
 
        echo
        # Note: for quota accounting (not enforcement), EDQUOT is not expected
@@ -167,24 +161,27 @@ _exercise()
                _file_as_id $SCRATCH_MNT/hard$i $id $type 1024 0
        done
        _qmount
-       xfs_quota -D $tmp.projects -P $tmp.projid -x \
+       $XFS_QUOTA_PROG -x  -c "warn -b -$type 0 $id" \
+               -c "warn -i -$type 0 $id" $SCRATCH_DEV
+       $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
                -c "repquota -birnN -$type" $SCRATCH_DEV |
-               _filter_report | LC_COLLATE=POSIX sort -ru
+               _filter_quota_report | LC_COLLATE=POSIX sort -ru
 
        echo
        # Note: for quota accounting (not enforcement), EDQUOT is not expected
        echo "*** push past the hard block limit (expect EDQUOT)" | tee -a $seqres.full
-       _file_as_id $SCRATCH_MNT/softie $id $type 1024 540
+       _file_as_id $SCRATCH_MNT/softie $id $type $bsize 1200
        echo "ls -l $SCRATCH_MNT" >>$seqres.full
        ls -l $SCRATCH_MNT >>$seqres.full
        _qmount
-       xfs_quota -D $tmp.projects -P $tmp.projid -x \
+       $XFS_QUOTA_PROG -x -c "warn -b -$type 0 $id" $SCRATCH_DEV
+       $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
                -c "repquota -birnN -$type" $SCRATCH_DEV |
                _filter_and_check_blks | LC_COLLATE=POSIX sort -ru
 
        echo
        echo "*** unmount"
-       umount $SCRATCH_MNT
+       _scratch_unmount
 
 }
 
@@ -200,38 +197,28 @@ EOF
 projid_file="$tmp.projid"
 
 echo "*** user"
-if [ "$HOSTOS" == "IRIX" ]
-then
-       _qmount_option "quota"
-else
-       _qmount_option "uquota"
-fi
-_exercise
+_qmount_option "uquota"
+_exercise u
 
 echo "*** group"
 _qmount_option "gquota"
-_exercise
+_exercise g
 
 echo "*** uqnoenforce"
-if [ "$HOSTOS" == "IRIX" ]
-then
-       _qmount_option "qnoenforce"
-else
-       _qmount_option "uqnoenforce"
-fi
-_exercise
+_qmount_option "uqnoenforce"
+_exercise uno
 
 echo "*** gqnoenforce"
 _qmount_option "gqnoenforce"
-_exercise
+_exercise gno
 
 echo "*** pquota"
 _qmount_option "pquota"
-_exercise
+_exercise p
 
 echo "*** pqnoenforce"
 _qmount_option "pqnoenforce"
-_exercise
+_exercise pno
 
 # success, all done
 status=0