]> 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:28:33 +0000 (19:28 -0500)
commit43023d8a7d98736d76ed41fced9a9f637678215f
tree7783554389b4b58af7fb057553c3a1d5dbd61998
parent23d07ee01743d6188ef4a579903d40aab2f1ff6b
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.

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
fs/btrfs/ctree.h
fs/btrfs/file.c
fs/btrfs/file.h
fs/btrfs/inode.c
fs/btrfs/reflink.c