[PATCH 4/4] btrfs: honor FMODE_NOCMTIME when cloning
From: Jeff Layton
Date: Thu Nov 05 2026 - 15:41:16 EST
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@xxxxxxxxxx>
---
fs/btrfs/file.c | 2 +-
fs/btrfs/file.h | 1 +
fs/btrfs/reflink.c | 3 ++-
3 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 6ff494846aea..6f525ce42a2d 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -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);
}
diff --git a/fs/btrfs/file.h b/fs/btrfs/file.h
index 18ebc8c2d6d2..9e35db3f4466 100644
--- a/fs/btrfs/file.h
+++ b/fs/btrfs/file.h
@@ -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);
diff --git a/fs/btrfs/reflink.c b/fs/btrfs/reflink.c
index f67350bba9b9..5154db82ef3e 100644
--- a/fs/btrfs/reflink.c
+++ b/fs/btrfs/reflink.c
@@ -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;
--
2.56.0