]> git.hungrycats.org Git - linux/commitdiff
btrfs: use aligned range for locking in reflink
authorQu Wenruo <wqu@suse.com>
Tue, 28 Jul 2026 09:11:23 +0000 (18:41 +0930)
committerDavid Sterba <dsterba@suse.com>
Fri, 7 Aug 2026 17:17:18 +0000 (19:17 +0200)
In btrfs_extent_same_range() and btrfs_clone_files(), the range passed
into btrfs_lock_extent() is not aligned at its end, because we can
reflink until the EOF, which may not be block aligned.

Although this is not a big deal, for the sake of consistency, and to
prepare for the upcoming stricter alignment check, pass an aligned range
end to btrfs_lock_extent() and btrfs_unlock_extent().

Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/reflink.c

index ec6a760519d9e10f86766d8192ec8e4c9e705600..d2a4101912bdb290764619aadf6f9d0df4b56a14 100644 (file)
@@ -687,10 +687,10 @@ static void btrfs_double_mmap_unlock(struct btrfs_inode *inode1, struct btrfs_in
 static int btrfs_extent_same_range(struct btrfs_inode *src, u64 loff, u64 len,
                                   struct btrfs_inode *dst, u64 dst_loff)
 {
-       const u64 end = dst_loff + len - 1;
        struct extent_state *cached_state = NULL;
        struct btrfs_fs_info *fs_info = src->root->fs_info;
        const u32 bs = fs_info->sectorsize;
+       const u64 end = round_up(dst_loff + len, bs) - 1;
        int ret;
 
        /*
@@ -799,7 +799,7 @@ static noinline int btrfs_clone_files(struct file *file, struct file *file_src,
         * because we have already locked the inode's i_mmap_lock in exclusive
         * mode.
         */
-       end = destoff + len - 1;
+       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);
        btrfs_unlock_extent(&inode->io_tree, destoff, end, &cached_state);