]> git.hungrycats.org Git - linux/commitdiff
btrfs: honor FMODE_NOCMTIME when cloning 6.18/topics/nocmtime
authorJeff Layton <jlayton@kernel.org>
Thu, 5 Nov 2026 20:07:45 +0000 (15:07 -0500)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Mon, 9 Nov 2026 00:18:39 +0000 (19:18 -0500)
btrfs_remap_file_range() calls generic_remap_file_range_prep() through
btrfs_remap_file_range_prep(). The file_modified() call in
generic_remap_file_range_prep() skips the c/mtime update for
FMODE_NOCMTIME files, but btrfs_clone_files() then always tells
btrfs_clone() to update the c/mtime of the destination.

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

Pass no_time_update for FMODE_NOCMTIME destinations, as dedupe already
does. Make btrfs_should_update_cmtime() available to reflink.c.

[zygo: 6.18 backport: 6.18's btrfs_clone_files() locks up to destoff +
len - 1 and passes 0 as no_time_update; 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-4-a42a2b93cdc2@kernel.org
Assisted-by: Claude:claude-opus-5-5
fs/btrfs/file.c
fs/btrfs/file.h
fs/btrfs/reflink.c

index e0dd846fe4e0045e531c3b68290a349b515764a6..46e78c97557d60492091dcd261ef1a9ba4592d30 100644 (file)
@@ -1036,7 +1036,7 @@ void btrfs_check_nocow_unlock(struct btrfs_inode *inode)
  * with FMODE_NOCMTIME (e.g. by nfsd while a client holds delegated
  * timestamps).
  */
-static bool btrfs_should_update_cmtime(const struct file *file)
+bool btrfs_should_update_cmtime(const struct file *file)
 {
        return !IS_NOCMTIME(file_inode(file)) && !(file->f_mode & FMODE_NOCMTIME);
 }
index 18ebc8c2d6d28b375e24bad22615103d2b1f7508..9e35db3f4466353d58049cc98c904d5894d528a0 100644 (file)
@@ -43,6 +43,7 @@ int btrfs_fdatawrite_range(struct btrfs_inode *inode, loff_t start, loff_t end);
 int btrfs_check_nocow_lock(struct btrfs_inode *inode, loff_t pos,
                           size_t *write_bytes, bool nowait);
 void btrfs_check_nocow_unlock(struct btrfs_inode *inode);
+bool btrfs_should_update_cmtime(const struct file *file);
 bool btrfs_find_delalloc_in_range(struct btrfs_inode *inode, u64 start, u64 end,
                                  struct extent_state **cached_state,
                                  u64 *delalloc_start_ret, u64 *delalloc_end_ret);
index c70d9e44fbda4588f7beaecd5eef21a7ad295cce..696b0769d62283ba4b59880c0339fa98b7693d42 100644 (file)
@@ -803,7 +803,8 @@ static noinline int btrfs_clone_files(struct file *file, struct file *file_src,
         */
        end = destoff + len - 1;
        btrfs_lock_extent(&BTRFS_I(inode)->io_tree, destoff, end, &cached_state);
-       ret = btrfs_clone(src, inode, off, olen, len, destoff, 0);
+       ret = btrfs_clone(src, inode, off, olen, len, destoff,
+                         !btrfs_should_update_cmtime(file));
        btrfs_unlock_extent(&BTRFS_I(inode)->io_tree, destoff, end, &cached_state);
 
        /*