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