]> git.apps.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
generic: make 17[1-4] work well when btrfs compression is enabled
authorWang Xiaoguang <wangxg.fnst@cn.fujitsu.com>
Wed, 2 Nov 2016 04:07:27 +0000 (12:07 +0800)
committerEryu Guan <eguan@redhat.com>
Tue, 13 Dec 2016 06:26:18 +0000 (14:26 +0800)
When enabling btrfs compression, original codes can not fill fs
correctly, here we introduce _fill_fs() in common/rc, which'll keep
creating and writing files until enospc error occurs. Note _fill_fs
is copied from tests/generic/256, but with some minor modifications.

Signed-off-by: Wang Xiaoguang <wangxg.fnst@cn.fujitsu.com>
Reviewed-by: Eryu Guan <eguan@redhat.com>
Signed-off-by: Eryu Guan <eguan@redhat.com>
common/populate
tests/generic/171
tests/generic/172
tests/generic/173
tests/generic/174
tests/generic/256

index d0003c5ec197a72ad94456497d0a7199ce322c13..df6550d49ae3a911e74216bf665b4ec18a2cc357 100644 (file)
@@ -538,3 +538,70 @@ _scratch_fuzz_test() {
        (find "${SCRATCH_MNT}/test.1/" -type f -size -1048576k -print0 | xargs -0 cat) >/dev/null 2>&1
 }
 
+# Fill a file system by repeatedly creating files in the given folder
+# starting with the given file size.  Files are reduced in size when
+# they can no longer fit until no more files can be created.
+_fill_fs()
+{
+       local file_size=$1
+       local dir=$2
+       local block_size=$3
+       local switch_user=$4
+       local file_count=1
+       local bytes_written=0
+       local use_falloc=1;
+
+       if [ $# -ne 4 ]; then
+               echo "Usage: _fill_fs filesize dir blocksize switch_user"
+               exit 1
+       fi
+
+       if [ $switch_user -eq 0 ]; then
+               mkdir -p $dir
+       else
+               _user_do "mkdir -p $dir"
+       fi
+       if [ ! -d $dir ]; then
+               return 0;
+       fi
+
+       testio=`$XFS_IO_PROG -F -fc "falloc 0 $block_size" $dir/$$.xfs_io 2>&1`
+       echo $testio | grep -q "not found" && use_falloc=0
+       echo $testio | grep -q "Operation not supported" && use_falloc=0
+
+       if [ $file_size -lt $block_size ]; then
+               $file_size = $block_size
+       fi
+
+       while [ $file_size -ge $block_size ]; do
+               bytes_written=0
+               if [ $switch_user -eq 0 ]; then
+                       if [ $use_falloc -eq 0 ]; then
+                               $XFS_IO_PROG -fc "pwrite -b 8388608 0 $file_size" \
+                                       $dir/$file_count
+                       else
+                               $XFS_IO_PROG -fc "falloc 0 $file_size" \
+                                       $dir/$file_count
+                       fi
+               else
+                       if [ $use_falloc -eq 0 ]; then
+                               _user_do "$XFS_IO_PROG -f -c \"pwrite -b 8388608 0 \
+                                       $file_size\" $dir/$file_count"
+                       else
+                               _user_do "$XFS_IO_PROG -f -c \"falloc 0 \
+                                       $file_size\" $dir/$file_count"
+                       fi
+               fi
+
+               if [ -f $dir/$file_count ]; then
+                       bytes_written=$(stat -c '%s' $dir/$file_count)
+               fi
+
+               # If there was no room to make the file, then divide it in
+               # half, and keep going
+               if [ $bytes_written -lt $file_size ]; then
+                       file_size=$((file_size / 2))
+               fi
+               file_count=$((file_count + 1))
+       done
+}
index b01dbd5cd2971ba6ec795b22d85a87b87563237c..916d66354d79f9d62dbd4927f1f4c66a89c0a416 100755 (executable)
@@ -38,6 +38,7 @@ _cleanup()
 
 # get standard environment, filters and checks
 . ./common/rc
+. ./common/populate
 . ./common/filter
 . ./common/attr
 . ./common/reflink
@@ -76,8 +77,7 @@ sync
 
 echo "Allocate the rest of the space"
 nr_free=$(stat -f -c '%f' $testdir)
-touch $testdir/file0 $testdir/file1
-_pwrite_byte 0x61 0 $((blksz * nr_free)) $testdir/eat_my_space >> $seqres.full 2>&1
+_fill_fs $((nr_free * blksz)) $testdir/space $blksz 0 >> $seqres.full 2>&1
 sync
 
 echo "CoW the big file"
index 0cbcc1f37916295f3eb0e8b60f622cf10c3f4278..2727836b82dd3f54111ef011a109270887f39b39 100755 (executable)
@@ -38,6 +38,7 @@ _cleanup()
 
 # get standard environment, filters and checks
 . ./common/rc
+. ./common/populate
 . ./common/filter
 . ./common/attr
 . ./common/reflink
@@ -57,6 +58,7 @@ testdir=$SCRATCH_MNT/test-$seq
 mkdir $testdir
 
 echo "Reformat with appropriate size"
+blksz="$(get_block_size $testdir)"
 umount $SCRATCH_MNT
 
 file_size=$((168 * 1024 * 1024))
@@ -72,8 +74,7 @@ _cp_reflink $testdir/bigfile $testdir/clonefile
 sync
 
 echo "Allocate the rest of the space"
-touch $testdir/file0 $testdir/file1
-_pwrite_byte 0x61 0 $fs_size $testdir/eat_my_space >> $seqres.full 2>&1
+_fill_fs $fs_size  $testdir/space $blksz 0 >> $seqres.full 2>&1
 sync
 
 echo "CoW the big file"
index e35597f5e7f6c2b02efdbc1162f77f41b44112a9..a414c8e1a2261caba3351f9526b851eb1e96f6e0 100755 (executable)
@@ -38,6 +38,7 @@ _cleanup()
 
 # get standard environment, filters and checks
 . ./common/rc
+. ./common/populate
 . ./common/filter
 . ./common/attr
 . ./common/reflink
@@ -76,8 +77,7 @@ sync
 
 echo "Allocate the rest of the space"
 nr_free=$(stat -f -c '%f' $testdir)
-touch $testdir/file0 $testdir/file1
-_pwrite_byte 0x61 0 $((blksz * nr_free)) $testdir/eat_my_space >> $seqres.full 2>&1
+_fill_fs $((blksz * nr_free)) $testdir/space $blksz 0 >> $seqres.full 2>&1
 sync
 
 echo "mmap CoW the big file"
index 38fad1d40de5eb14974ecdc95917810f9d7455c5..1eeff690b2aeef0fcea2dcb15e3bc95bf78ac69f 100755 (executable)
@@ -38,6 +38,7 @@ _cleanup()
 
 # get standard environment, filters and checks
 . ./common/rc
+. ./common/populate
 . ./common/filter
 . ./common/attr
 . ./common/reflink
@@ -77,8 +78,7 @@ sync
 
 echo "Allocate the rest of the space"
 nr_free=$(stat -f -c '%f' $testdir)
-touch $testdir/file0 $testdir/file1
-_pwrite_byte 0x61 0 $((blksz * nr_free)) $testdir/eat_my_space >> $seqres.full 2>&1
+_fill_fs $((blksz * nr_free)) $testdir/space $blksz 0 >> $seqres.full 2>&1
 sync
 
 echo "CoW the big file"
index cfbf7909f15712c0e131dbcdf75a5d70561d3fff..63f2d4f4108efe39072984715e8e2f1711b00a6b 100755 (executable)
@@ -39,6 +39,7 @@ trap "_cleanup ; exit \$status" 0 1 2 3 15
 
 # get standard environment, filters and checks
 . ./common/rc
+. ./common/populate
 . ./common/filter
 . ./common/punch
 
@@ -53,64 +54,6 @@ _require_test
 
 testfile=$TEST_DIR/256.$$
 
-# _fill_fs()
-#
-# Fills a file system by repeatedly creating files in the given folder
-# starting with the given file size.  Files are reduced in size when
-# they can no longer fit untill no more files can be created.
-#
-# This routine is used by _test_full_fs_punch to test that a hole may
-# still be punched when the disk is full by borrowing reserved blocks.
-# All files are created as a non root user to prevent reserved blocks
-# from being consumed.
-#
-_fill_fs() {
-       local file_size=$1
-       local dir=$2
-       local block_size=$3
-       local file_count=1
-       local bytes_written=0
-
-       if [ $# -ne 3 ]
-       then
-               echo "USAGE: _fill_fs filesize dir block size"
-               exit 1
-       fi
-
-       # Creation of files or folders
-       # must not be done as root or
-       # reserved blocks will be consumed
-       _user_do "mkdir -p $dir &> /dev/null"
-       if [ $? -ne 0 ] ; then
-               return 0
-       fi
-
-       if [ $file_size -lt $block_size ]
-       then
-               $file_size = $block_size
-       fi
-
-       while [ $file_size -ge $block_size ]
-       do
-               bytes_written=0
-               _user_do "$XFS_IO_PROG -f -c \"pwrite 0 $file_size\" $dir/$file_count.bin &> /dev/null"
-
-               if [ -f $dir/$file_count.bin ]
-               then
-                       bytes_written=`$XFS_IO_PROG -c "stat"  $dir/$file_count.bin | grep stat.size | cut -d ' ' -f3`
-               fi
-
-               # If there was no room to make the file,
-               # then divide it in half, and keep going
-               if [ $bytes_written -lt $file_size ]
-               then
-                       file_size=$(( $file_size / 2 ))
-               fi
-               file_count=$(( $file_count + 1 ))
-
-       done
-}
-
 # _test_full_fs_punch()
 #
 # This function will test that a hole may be punched
@@ -144,7 +87,10 @@ _test_full_fs_punch()
                -c "fsync" $file_name &> /dev/null
        chmod 666 $file_name
 
-       _fill_fs $(( 1024 * 1024 * 1024 )) $path/fill $block_size
+       # All files are created as a non root user to prevent reserved blocks
+       # from being consumed.
+       _fill_fs $(( 1024 * 1024 * 1024 )) $path/fill $block_size 1 \
+               > /dev/null 2>&1
 
        for (( i=0; i<$iterations; i++ ))
        do
@@ -159,7 +105,7 @@ _test_full_fs_punch()
 
                hole_offset=$(( $hole_offset + $hole_len + $hole_interval ))
 
-               _fill_fs $hole_len $path/fill.$i $block_size
+               _fill_fs $hole_len $path/fill.$i $block_size 1 > /dev/null 2>&1
 
        done
 }