generic: test number of blocks used by a file after mwrite into a hole
authorFilipe Manana <fdmanana@suse.com>
Wed, 4 Nov 2020 11:13:37 +0000 (11:13 +0000)
committerEryu Guan <guaneryu@gmail.com>
Sun, 8 Nov 2020 07:07:09 +0000 (15:07 +0800)
Test that after doing a memory mapped write to an empty file, a call to
stat(2) reports a non-zero number of used blocks.

This is motivated by a bug in btrfs where the number of blocks used does
not change. It currenly fails on btrfs and it is fixed by a patch that
has the following subject:

  "btrfs: fix missing delalloc new bit for new delalloc ranges"

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
tests/generic/614 [new file with mode: 0755]
tests/generic/614.out [new file with mode: 0644]
tests/generic/group

diff --git a/tests/generic/614 b/tests/generic/614
new file mode 100755 (executable)
index 0000000..80edf9c
--- /dev/null
@@ -0,0 +1,50 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved.
+#
+# FS QA Test No. 614
+#
+# Test that after doing a memory mapped write to an empty file, a call to
+# stat(2) reports a non-zero number of used blocks.
+#
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+tmp=/tmp/$$
+status=1       # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+       cd /
+       rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# real QA test starts here
+_supported_fs generic
+_require_scratch
+
+rm -f $seqres.full
+
+_scratch_mkfs >>$seqres.full 2>&1
+_scratch_mount
+
+$XFS_IO_PROG -f -c "truncate 64K"      \
+            -c "mmap -w 0 64K"        \
+            -c "mwrite -S 0xab 0 64K" \
+            -c "munmap"               \
+            $SCRATCH_MNT/foobar | _filter_xfs_io
+
+blocks_used=$(stat -c %b $SCRATCH_MNT/foobar)
+if [ $blocks_used -eq 0 ]; then
+    echo "error: stat(2) reported 0 used blocks"
+fi
+
+echo "Silence is golden"
+
+status=0
+exit
diff --git a/tests/generic/614.out b/tests/generic/614.out
new file mode 100644 (file)
index 0000000..3db7023
--- /dev/null
@@ -0,0 +1,2 @@
+QA output created by 614
+Silence is golden
index 31057ac8a67daa6507618d4e35c051e0a867cfb2..ab8ae74ed8195e9a3b6ae475b5837b3d4ddc2ace 100644 (file)
 611 auto quick attr
 612 auto quick clone
 613 auto quick encrypt
+614 auto quick rw