common/rc: generalize _get_filesize()
[xfstests-dev.git] / tests / xfs / 014
index 1e092a9566c7eb4983ac686f03eded33b3e38a72..be470a2dfc6ef7e8ebe2274a39894cbb3cf3d522 100755 (executable)
@@ -1,4 +1,7 @@
 #!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2014 Red Hat, Inc.  All Rights Reserved.
+#
 # FS QA Test No. xfs/014
 #
 # Test the behavior of XFS dynamic speculative preallocation at ENOSPC and
@@ -8,25 +11,6 @@
 # new writers reclaim said preallocations rather than prematurely fail with
 # ENOSPC/EDQUOT.
 #
-#-----------------------------------------------------------------------
-# Copyright (c) 2014 Red Hat, 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
 echo "QA output created by $seq"
@@ -44,7 +28,7 @@ _cleanup()
 {
        cd /
        umount $LOOP_MNT 2>/dev/null
-       umount $SCRATCH_MNT 2>/dev/null
+       _scratch_unmount 2>/dev/null
        rm -f $tmp.*
 }
 trap "_cleanup; exit \$status" 0 1 2 3 15
@@ -69,7 +53,7 @@ _spec_prealloc_file()
        # write a 4k aligned amount of data to keep the calculations simple
        $XFS_IO_PROG -c "pwrite 0 128m" $file >> $seqres.full
 
-       size=`stat -c "%s" $file`
+       size=`_get_filesize $file`
        blocks=`stat -c "%b" $file`
        blocksize=`stat -c "%B" $file`
 
@@ -88,7 +72,7 @@ _consume_free_space()
        dir=$1
 
        # allocate all but 10MB of available space
-       freesp=`df -m $dir | awk '/^\// { print $4 - 10 }'`
+       freesp=`$DF_PROG -m $dir | $AWK_PROG '/^\// { print $5 - 10 }'`
        $XFS_IO_PROG -f -c "falloc 0 ${freesp}M" $dir/spc
 }
 
@@ -111,6 +95,9 @@ _test_enospc()
 
        # consume 1/2 of the current preallocation across the set of 4 writers
        write_size=$((TOTAL_PREALLOC / 2 / 4))
+       for i in $(seq 0 3); do
+               touch $dir/file.$i
+       done
        for i in $(seq 0 3); do
                $XFS_IO_PROG -f -c "pwrite 0 $write_size" $dir/file.$i \
                        >> $seqres.full &
@@ -145,7 +132,7 @@ _test_edquot()
        blks=`$XFS_QUOTA_PROG -xc "quota -u $qa_user" $dir | \
                tail -n 1 | awk '{ print $2 }'`
        $XFS_QUOTA_PROG -xc "limit -u bhard=${blks}k $qa_user" $dir
-       blks=`$XFS_QUOTA_PROG -xc "quota -g $qa_grup" $dir | \
+       blks=`$XFS_QUOTA_PROG -xc "quota -g $qa_group" $dir | \
                tail -n 1 | awk '{ print $2 }'`
        $XFS_QUOTA_PROG -xc "limit -g bhard=${blks}k $qa_group" $dir
 
@@ -193,8 +180,7 @@ umount $LOOP_MNT
 
 echo $orig_sp_time > /proc/sys/fs/xfs/speculative_prealloc_lifetime
 
-umount $SCRATCH_MNT
-_check_scratch_fs
+_scratch_unmount
 
 status=0
 exit