]> git-server-git.apps.pok.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
common: new helper to alloacate fixed size files
authorPavel Reichl <preichl@redhat.com>
Thu, 22 Sep 2022 06:38:35 +0000 (08:38 +0200)
committerZorro Lang <zlang@kernel.org>
Fri, 23 Sep 2022 01:13:35 +0000 (09:13 +0800)
Helper that creates files of specified size using falloc if supported,
otherwise pwrite is used.

Signed-off-by: Pavel Reichl <preichl@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Zorro Lang <zlang@redhat.com>
Signed-off-by: Zorro Lang <zlang@kernel.org>
common/rc
tests/generic/694

index 07c4803a12f3e003f5a9cc93e9737047c50805db..d1f3d56bf82627166e7a15c6f5a97c413db004cd 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -4925,6 +4925,29 @@ hexdump()
        _fail "Use _hexdump(), please!"
 }
 
+# Try to create a file with inode->i_blocks >= (length / blocksize).
+# There may be some small overhead, e.g. ext2 filesystem allocates a
+# substantial number of blocks to store block mappings. Those are accounted
+# to i_blocks.
+_create_file_sized()
+{
+       local length=$1
+       local file=$2
+       local tmp=`mktemp -u`
+       local ret=0
+
+       $XFS_IO_PROG -ft -c "falloc 0 $length" $file >$tmp.out 2>&1
+       ret=$?
+       if (grep -Eq "Operation not supported|command .* not found" $tmp.out);then
+               # fallocate isn't supported, fallback to general buffer write
+               $XFS_IO_PROG -ft -c "pwrite 0 $length" $file >$tmp.out 2>&1
+               ret=$?
+       fi
+       [ $ret -ne 0 ] && cat $tmp.out
+       rm -f $tmp.out
+       return $ret
+}
+
 init_rc
 
 ################################################################################
index dfd988dfac39ead6cddc2b60a139b43bb6232beb..c96c2154fdb9e09afd8f4a1ea200acb50a9365e1 100755 (executable)
@@ -21,6 +21,9 @@ _cleanup()
 }
 
 _supported_fs generic
+_fixed_by_kernel_commit 0c336d6e33f4 \
+       "exfat: fix incorrect loading of i_blocks for large file"
+
 _require_test
 _require_fs_space $TEST_DIR $((4 * 1024 * 1024)) #kB
 
@@ -30,7 +33,10 @@ junk_dir=$TEST_DIR/$seq
 junk_file=$junk_dir/junk
 mkdir -p $junk_dir
 
-$XFS_IO_PROG -f -c "pwrite -W 0 4G" $junk_file > /dev/null
+_create_file_sized 4G $junk_file
+if [ $? -ne 0 ]; then
+       echo "Could not create 4G test file"
+fi
 
 iblocks=`stat -c '%b' $junk_file`