* [PATCH 6.6.y] smb: client: don't truncate the file when punching a hole
@ 2026-12-04 10:38 Mark Syms
2026-12-04 19:49 ` Sasha Levin
0 siblings, 1 reply; 2+ messages in thread
From: Mark Syms @ 2026-12-04 10:38 UTC (permalink / raw)
To: stable
Cc: Mark Syms, linux-cifs, Steve French, Paulo Alcantara,
David Howells, Greg Kroah-Hartman, Sasha Levin
smb3_punch_hole() moves the server's EOF out to cover dirty data whose
size update the local hole punch dropped, and decides whether to from the
netfs remote_i_size. This tree's cifs does not maintain remote_i_size: it
is set at inode init and on copy/clone only, so for any file that has
grown since, the "extension" truncates the file to the end of the hole:
truncate -s 64M f; fallocate -p -o 1M -l 512k f -> 1572864 bytes
qemu passes guest discards through as punch holes, so a guest's first
discard cuts its image short and every block allocated above the hole is
lost.
Ask the server for its EOF instead, so the call can only grow the file.
Fixes: 288d398df80c ("cifs: Fix FALLOC_FL_PUNCH_HOLE support")
Assisted-by: Claude:claude-opus-5-5 checkpatch
Signed-off-by: Mark Syms <mark.syms@citrix.com>
---
This is a fix for 6.6.y only. Mainline is not affected: since the netfs
write conversion, remote_i_size is maintained on every write, so the
check in smb3_punch_hole() is correct there. 6.6 got the check from the
backport of 416871f4fb84 (6.6.49) without that maintenance, and every
6.6.y release since (checked through 6.6.163) truncates a file that has
grown since its inode was loaded when a hole is punched below its EOF.
It depends on query_server_eof() from 74f39fa28286 ("smb: client: only
require read lease for size extending ops"), which is in 6.6.163.
Found as qcow2 images on an SMB share being cut short by guest discards
passed through by qemu. Tested on 6.6.138 with the 6.6.158-163 smb
client fixes applied: the reproducer above keeps 67108864 bytes, and a
qemu-io discard/zero-range pattern test verifies clean.
fs/smb/client/smb2ops.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c
index 84acf669f88a..20b4072314bd 100644
--- a/fs/smb/client/smb2ops.c
+++ b/fs/smb/client/smb2ops.c
@@ -3414,15 +3414,25 @@ static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
* of the high end of the hole and the proposed EOF. The problem is
* that we locally hole-punch the tail of the dirty data, the proposed
* EOF update will end up in the wrong place.
+ *
+ * Ask the server where its EOF is: this tree does not maintain the
+ * netfs remote_i_size, and a stale one turns this into a truncation
+ * of everything beyond the hole.
*/
+ rc = query_server_eof(xid, tcon, cfile, &remote_i_size);
+ if (rc)
+ goto unlock;
i_size = i_size_read(inode);
- remote_i_size = netfs_inode(inode)->remote_i_size;
if (end > remote_i_size && i_size > remote_i_size) {
unsigned long long extend_to = umin(end, i_size);
rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
cfile->fid.volatile_fid, cfile->pid, extend_to);
- if (rc >= 0)
+ if (rc >= 0) {
netfs_inode(inode)->remote_i_size = extend_to;
+ spin_lock(&inode->i_lock);
+ CIFS_I(inode)->server_eof = extend_to;
+ spin_unlock(&inode->i_lock);
+ }
}
unlock:
--
2.56.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 6.6.y] smb: client: don't truncate the file when punching a hole
2026-12-04 10:38 [PATCH 6.6.y] smb: client: don't truncate the file when punching a hole Mark Syms
@ 2026-12-04 19:49 ` Sasha Levin
0 siblings, 0 replies; 2+ messages in thread
From: Sasha Levin @ 2026-12-04 19:49 UTC (permalink / raw)
To: stable
Cc: Sasha Levin, Mark Syms, linux-cifs, Steve French, Paulo Alcantara,
David Howells, Greg Kroah-Hartman
> This is a fix for 6.6.y only. Mainline is not affected: since the netfs
> write conversion, remote_i_size is maintained on every write, so the
> check in smb3_punch_hole() is correct there.
Since this is a stable-only change with no upstream commit, I'd like an
Acked-by or Reviewed-by from the smb client side before queueing it for 6.6.
Paulo, David, could one of you take a look?
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-04 19:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 10:38 [PATCH 6.6.y] smb: client: don't truncate the file when punching a hole Mark Syms
2026-12-04 19:49 ` Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox