Skip to content

testsuite: probe the punch granularity each hole assertion relies on - #1062

Merged
steadytao merged 1 commit into
RsyncProject:masterfrom
samueloph:testsuite-punch-granularity
Aug 19, 2026
Merged

testsuite: probe the punch granularity each hole assertion relies on#1062
steadytao merged 1 commit into
RsyncProject:masterfrom
samueloph:testsuite-punch-granularity

Conversation

@samueloph

Copy link
Copy Markdown
Member

The last section of preallocate_test.py writes 256 blocks of [4 KiB data][24 KiB zeros][4 KiB data] and requires --inplace --sparse to deallocate at least half of the file. A punch only frees whole allocation units, and that interior run sits 4 KiB into each 32 KiB block: with a 4 KiB unit it covers six whole units (24 KiB freed per block), but with a 16 KiB unit it covers none at all -- [0,16K) holds live data at [0,4K) and [16K,32K) holds live data at [28K,32K) -- so st_blocks cannot move whatever rsync does.

That fails the build on Debian loong64, whose kernel uses 16 KiB pages:

--inplace --sparse left matching interior zero runs allocated: 8388608 of
8388608 bytes remain allocated after a 8388608-byte matched-block update

i.e. exactly "nothing was freed". fs_can_punch_holes() does not catch it because it punches a whole 64 KiB file, which frees blocks at any granularity.

Generalise that helper into punch_frees(offset, length, size) so each assertion can probe the shape it actually depends on, and gate the interior one on the exact layout written just above it. Where the filesystem can free that run the assertion runs exactly as before; where it cannot, the test says so rather than reporting a regression. The content check is unconditional either way.

While here, call fallocate64() instead of fallocate(). ctypes declares the offset and length as c_longlong, but glibc's fallocate() takes 32-bit off_t where off_t is 32 bits, so the callee reads the high half of offset as its length, the call fails with EINVAL, and can_punch comes back False -- which is why none of this file's hole-punching assertions have ever run on a 32-bit port. On i386:

fs_can_punch_holes() as written : before=128 ret=-1 errno=22 -> False
the same probe via fallocate64 : before=128 ret=0 -> True

fallocate64() takes off64_t on every architecture and is a plain alias of fallocate() where off_t is already 64 bits. The probe also writes urandom rather than a repeated byte, so a filesystem that compresses does not answer "nothing was freed" merely because nothing was allocated.

Failing build log:
loong64 https://buildd.debian.org/status/fetch.php?pkg=rsync&arch=loong64&ver=3.5.0%2Bds1-1&stamp=1786938228&raw=0

The last section of preallocate_test.py writes 256 blocks of
[4 KiB data][24 KiB zeros][4 KiB data] and requires --inplace --sparse to
deallocate at least half of the file. A punch only frees whole allocation
units, and that interior run sits 4 KiB into each 32 KiB block: with a 4 KiB
unit it covers six whole units (24 KiB freed per block), but with a 16 KiB
unit it covers none at all -- [0,16K) holds live data at [0,4K) and [16K,32K)
holds live data at [28K,32K) -- so st_blocks cannot move whatever rsync does.
That fails the build on Debian loong64, whose kernel uses 16 KiB pages:
--inplace --sparse left matching interior zero runs allocated: 8388608 of
8388608 bytes remain allocated after a 8388608-byte matched-block update
i.e. exactly "nothing was freed". fs_can_punch_holes() does not catch it
because it punches a whole 64 KiB file, which frees blocks at any granularity.
Generalise that helper into punch_frees(offset, length, size) so each
assertion can probe the shape it actually depends on, and gate the interior
one on the exact layout written just above it. Where the filesystem can free
that run the assertion runs exactly as before; where it cannot, the test says
so rather than reporting a regression. The content check is unconditional
either way.
While here, call fallocate64() instead of fallocate(). ctypes declares the
offset and length as c_longlong, but glibc's fallocate() takes 32-bit off_t
where off_t is 32 bits, so the callee reads the high half of `offset` as its
`length`, the call fails with EINVAL, and can_punch comes back False -- which
is why none of this file's hole-punching assertions have ever run on a 32-bit
port. On i386:
fs_can_punch_holes() as written : before=128 ret=-1 errno=22 -> False
the same probe via fallocate64 : before=128 ret=0 -> True
fallocate64() takes off64_t on every architecture and is a plain alias of
fallocate() where off_t is already 64 bits. The probe also writes urandom
rather than a repeated byte, so a filesystem that compresses does not answer
"nothing was freed" merely because nothing was allocated.
Failing build log:
loong64 https://buildd.debian.org/status/fetch.php?pkg=rsync&arch=loong64&ver=3.5.0%2Bds1-1&stamp=1786938228&raw=0

@steadytaosteadytao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you for the PR.

@steadytao
steadytao merged commit 9371b33 into RsyncProject:masterAug 19, 2026
20 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@samueloph@steadytao