]> git.hungrycats.org Git - linux/commit
btrfs: honor FMODE_NOCMTIME when punching holes
authorJeff Layton <jlayton@kernel.org>
Thu, 5 Nov 2026 20:07:43 +0000 (15:07 -0500)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Mon, 9 Nov 2026 00:18:28 +0000 (19:18 -0500)
commit6a74c9828ec6d6228ebae87540bf292b543bc2e0
treea8bf76e249def7d3be8d04d4403eb024ba614401
parenta1a8b717073f8a6d007a64a0348eae3943ea769c
btrfs: honor FMODE_NOCMTIME when punching holes

btrfs_punch_hole() calls file_modified(), which skips the c/mtime update
for FMODE_NOCMTIME files. But btrfs_punch_hole() then updates c/mtime
itself in two places: after it replaces the extents, and in the
partial-block path. Also, when extent_info is NULL,
btrfs_replace_file_extents() updates c/mtime for each transaction.

nfsd sets FMODE_NOCMTIME while a client holds delegated timestamps. Thus
a DEALLOCATE from the holder advances the server's ctime, and the times
that the holder returns cannot move it back.

- Add btrfs_should_update_cmtime() and use it in btrfs_write_check() too.
- Replace btrfs_replace_extent_info::update_times with an update_times
  argument to btrfs_replace_file_extents(). This lets the NULL
  extent_info (hole punch) case skip the update.
- In btrfs_punch_hole(), skip the c/mtime updates for FMODE_NOCMTIME
  files.

The reflink caller that passes a NULL extent_info for a trailing hole
now also honors no_time_update, as clone_finish_inode_update() does.

[zygo: 6.18 backport: 6.18's btrfs_clone() takes struct inode * and
passes BTRFS_I(inode) to btrfs_replace_file_extents(); context adjusted,
the change itself is unchanged]

Fixes: e5e9b24ab8fa ("nfsd: freeze c/mtime updates with outstanding WRITE_ATTRS delegation")
Signed-off-by: Jeff Layton <jlayton@kernel.org>
Link: https://lore.kernel.org/r/20261105-delegts-btrfs-v1-2-a42a2b93cdc2@kernel.org
Assisted-by: Claude:claude-opus-5-5
fs/btrfs/ctree.h
fs/btrfs/file.c
fs/btrfs/file.h
fs/btrfs/inode.c
fs/btrfs/reflink.c