Subject: Re: bug#6131: [PATCH]: fiemap support for efficient sparse file copy

From: Jim Meyering <[email-masked]>
Date: Thu, 27 May 2010 22:26:50 +0200

Jim Meyering wrote:
> jeff.liu wrote:
>> Jim Meyering wrote:
>>> jeff.liu wrote:
>>>> This is the revised version, it fixed the fiemap-start offset calculation
>>>> approach to remove it out
>>>> of the 'for (i = 0; i < fiemap->fm_mapped_extents; i++)' loop.
>>>
>>> Hi Jeff,
>>>
>>> I've included below the state of my local changes.
>>> Unfortunately, with that 5-patch series, there is always a test failure
>>> on F13/ext4.  Maybe someone who knows more about extents can provide an
>>> explanation?
>>>
>>> Here's a small example to demonstrate:
>>>
>>> Create a file with many extents:
>>>
>>>     perl -e 'BEGIN { $n = 19 * 1024; *F = *STDOUT }' \
>>>       -e 'for (1..100) { sysseek (*F, $n, 1)' \
>>>       -e '&& syswrite (*F, "."x$n) or die "$!"}' > j1
>>>
>>> Using the patched "cp", repeat the following 10 or 20 times:
>>>
>>>     ./cp --sparse=always j1 j2; sync
>>>     filefrag -v j1 | awk '/^ / {print $1,$2}' > ff1 || fail=1
>>>     filefrag -v j2 | awk '/^ / {print $1,$2}' > ff2 || fail=1
>>>     diff -u ff1 ff2 || fail=1
>>>
>>> Usually there is no diff output, but occasionally it'll print this:
>>> [hmm... today it consistently prints these differences every other time.]
>> Woo!!!
>> I just run this test on btrfs/ext4/ocfs2 against mainline kernel(Linux jeff-laptop
>> 2.6.33-rc5-00238-gb04da8b-dirty) on my laptop.
>> Only btrfs always works well for me, Ext4 has the same issue like yours.
>
> One more point of reference:
> the tests all passed on an XFS file system.

Since XFS is relatively stable, I'll use it instead of ext4.
This incremental will permit use of either XFS or btrfs
for this test, as non-root, and otherwise, create an XFS
loopback partition when run as root:

diff --git a/tests/cp/sparse-fiemap b/tests/cp/sparse-fiemap
index ef3742e..763c3b7 100755
--- a/tests/cp/sparse-fiemap
+++ b/tests/cp/sparse-fiemap
@@ -23,8 +23,8 @@ fi

 . $srcdir/test-lib.sh

-if df -T -t ext4 . ; then
-  : # Current dir is on an ext4 partition.  Good!
+if df -T -t btrfs -t xfs . ; then
+  : # Current dir is on a partition with working extents.  Good!
 else
   # It's not;  we need to create one, hence we need root access.
   require_root_
@@ -33,18 +33,18 @@ else
   cleanup_() { cd /; umount "$cwd/mnt"; }

   skip=0
-  # Create an ext4 loopback file system
-  dd if=/dev/zero of=blob bs=8192 count=1000 || skip=1
+  # Create an XFS loopback file system
+  dd if=/dev/zero of=blob bs=32k count=1000 || skip=1
   mkdir mnt
-  mkfs -t ext4 -F blob ||
-    skip_test_ "failed to create ext4 file system"
+  mkfs -t xfs blob ||
+    skip_test_ "failed to create XFS file system"
   mount -oloop blob mnt   || skip=1
   cd mnt                  || skip=1
   echo test > f           || skip=1
   test -s f               || skip=1

   test $skip = 1 &&
-    skip_test_ "insufficient mount/ext4 support"
+    skip_test_ "insufficient mount/XFS support"

 fi