]> git.hungrycats.org Git - linux/commitdiff
btrfs: honor FMODE_NOCMTIME when cloning misc-next/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:28:30 +0000 (19:28 -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.

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

index 6ff494846aeaf224dace3977d416af09015c7152..6f525ce42a2d87beac1d843461a189dd49a673f1 100644 (file)
@@ -1030,7 +1030,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 f67350bba9b9f88b40660e3d14638d056f015ddc..5154db82ef3efd0ebd96830bbc9583e15654aaa1 100644 (file)
@@ -801,7 +801,8 @@ static noinline int btrfs_clone_files(struct file *file, struct file *file_src,
         */
        end = round_up(destoff + len, bs) - 1;
        btrfs_lock_extent(&inode->io_tree, destoff, end, &cached_state);
-       ret = btrfs_clone(src, inode, off, olen, len, destoff, false);
+       ret = btrfs_clone(src, inode, off, olen, len, destoff,
+                         !btrfs_should_update_cmtime(file));
        btrfs_unlock_extent(&inode->io_tree, destoff, end, &cached_state);
        if (ret < 0)
                return ret;