]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
smb/client: update i_blocks after contiguous writes
authorHuiwen He <hehuiwen@kylinos.cn>
Fri, 5 Jun 2026 16:35:17 +0000 (00:35 +0800)
committerSteve French <stfrench@microsoft.com>
Sun, 14 Jun 2026 20:12:23 +0000 (15:12 -0500)
commitaf25ab681ea0cead031379c8dcb112678a2e1cf6
tree8283d34323008d51eef2309884ef372235997ca3
parente8a5cf2ff5a13fefb228f2069e29dd7d8e37185d
smb/client: update i_blocks after contiguous writes

When a lease allows CIFS to use cached inode attributes, getattr may
return the locally cached attributes instead of revalidating them from
the server. After local writes extend a file, the write path updates the
file size, but i_blocks can remain based on the old allocation size.

For example, while the file is still open after two contiguous writes,
the local block count can remain smaller than the written range:

        after first write:   st_size = 4096,  st_blocks = 7
        after second write:  st_size = 12288, st_blocks = 21
        after close:         st_size = 12288, st_blocks = 24

This can make a fully written file look sparse:

        i_blocks * 512 < i_size

and can cause swap activation to reject a valid write-created swapfile
as having holes. This results in xfstests skipping swap-related tests
on CIFS mounts:

generic/472         [not run] swapfiles are not supported
generic/494         [not run] swapfiles are not supported
generic/497         [not run] swapfiles are not supported
generic/569         [not run] swapfiles are not supported
generic/636         [not run] swapfiles are not supported
generic/643         [not run] swapfiles are not supported

Update the local i_blocks estimate after successful writes, but only
when the write starts at or before the currently known allocated range.
This lets sequential writes grow i_blocks while avoiding treating
write-past-EOF holes as allocated.

Skip the local estimate for files that are already marked sparse, since
their allocation needs to come from the server rather than from a
contiguous-write estimate.

Signed-off-by: Huiwen He <hehuiwen@kylinos.cn>
Reviewed-by: ChenXiaoSong <chenxiaosong@kylinos.cn>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/client/cifsfs.c
fs/smb/client/cifsfs.h
fs/smb/client/cifsglob.h
fs/smb/client/file.c