740027
From: Pádraig Brady <pbrady@redhat.com>
740027
740027
Avoid false failure due to speculative preallocation on XFS
740027
Avoid false failure due to delayed allocation on BTRFS
740027
740027
diff -Naur coreutils-8.22.orig/tests/dd/sparse.sh coreutils-8.22/tests/dd/sparse.sh
740027
--- coreutils-8.22.orig/tests/dd/sparse.sh	2013-12-04 14:48:30.000000000 +0000
740027
+++ coreutils-8.22/tests/dd/sparse.sh	2015-05-19 21:24:55.139941789 +0000
740027
@@ -58,11 +58,18 @@
740027
 
740027
   # Ensure NUL blocks smaller than the block size are not made sparse.
740027
   # Here, with a 2MiB block size, dd's conv=sparse must *not* introduce a hole.
740027
-  dd if=file.in of=file.out bs=2M conv=sparse
740027
+  dd if=file.in of=file.out bs=2M conv=sparse,fsync
740027
   test 2500 -lt $(kb_alloc file.out) || fail=1
740027
 
740027
+  # Note we recreate a sparse file first to avoid
740027
+  # speculative preallocation seen in XFS, where a write() that
740027
+  # extends a file can preallocate some extra space that
740027
+  # a subsequent seek will not convert to a hole.
740027
+  rm -f file.out
740027
+  truncate --size=3M file.out
740027
+
740027
   # Ensure that this 1MiB string of NULs *is* converted to a hole.
740027
-  dd if=file.in of=file.out bs=1M conv=sparse
740027
+  dd if=file.in of=file.out bs=1M conv=sparse,notrunc,fsync
740027
   test $(kb_alloc file.out) -lt 2500 || fail=1
740027
 
740027
 fi