Subject: bug#79267: cp --sparse=auto heuristic fails on a squashfs mounted drive.

From: Pádraig Brady <[email-masked]>
Date: Sat, 23 Aug 2025 19:01:09 +0100

On 23/08/2025 01:48, Paul Eggert wrote:
> On 8/22/25 07:04, Pádraig Brady wrote:
>>         /* Copy this extent, looking for further opportunities to not
>>            bother to write zeros if --sparse=always, since SEEK_HOLE
>>            is conservative and may miss some holes.  */
>>
>> So the comment needs to be tweaked, but a more general issue
>> is that it disables copy offloading (copy_file_range) for sparse files.
> 
> Ouch, I didn't see that. That's a real loss. I installed the first
> attached patch to revert that part of my recent change.

Cool. I'll push the attached test to enforce this
> I assume the part of the change that always punches holes is OK. I
> couldn't see why one would not want to punch a hole if one has already
> taken the trouble to find and create the hole.

Fair enough. It simplifies the code anyway.

>> BTW commit 26bf557 also changed this a couple of weeks ago
>> without updating the comment, so the comment relates to sparse_mode !=
>> SPARSE_ALWAYS.
> 
> Not quite following but I hope the comment is OK now with the first
> patch installed.

Right, I missed that commit 26bf557 didn't actually change the logic
for this line, only the syntax.

thanks!
Padraig

From 6c668dc133af7d374790c1da666a701e21682a35 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email-masked]>
Date: Sat, 23 Aug 2025 18:53:17 +0100
Subject: [PATCH] tests: cp: ensure copy offload is not disabled for sparse
 files

Related to commits v9.1-109-g879d2180d and v9.7-248-g306de6c26

* tests/cp/sparse-perf.sh: This edge case was missed a couple of times,
so add a test to ensure we attempt copy offload.
---
 tests/cp/sparse-perf.sh | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/tests/cp/sparse-perf.sh b/tests/cp/sparse-perf.sh
index 8f737f798..5a283c1fe 100755
--- a/tests/cp/sparse-perf.sh
+++ b/tests/cp/sparse-perf.sh
@@ -18,8 +18,27 @@
 
 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 print_ver_ cp
+cleanup_() { rm -rf "$other_partition_tmpdir"; }
+. "$abs_srcdir/tests/other-fs-tmpdir"
+
+# Create a sparse file on another partition to avoid reflinking
+# thus exercising more copy logic
+
+other_partition_sparse=$other_partition_tmpdir/k
+printf x > $other_partition_sparse || framework_failure_
+truncate -s1M $other_partition_sparse || framework_failure_
+
+# cp should not disable anything by default, even for sparse files.  For e.g.
+# copy offload is an important performance improvement for sparse files on NFS.
+cp --debug $other_partition_sparse k2 >cp.out || fail=1
+cmp $other_partition_sparse k2 || fail=1
+grep ': avoided' cp.out && { cat cp.out; fail=1; }
+
+
+
+# Create a large-but-sparse file on the current partition.
+# We disable relinking below, thus verifying SEEK_HOLE support
 
-# Create a large-but-sparse file.
 timeout 10 truncate -s1T f ||
   skip_ "unable to create a 1 TiB sparse file"
 
-- 
2.50.1