Skip to content

Commit a5e6ea1

Browse files
fdmananakdave
authored andcommitted
fs: allow deduplication of eof block into the end of the destination file
We always round down, to a multiple of the filesystem's block size, the length to deduplicate at generic_remap_check_len(). However this is only needed if an attempt to deduplicate the last block into the middle of the destination file is requested, since that leads into a corruption if the length of the source file is not block size aligned. When an attempt to deduplicate the last block into the end of the destination file is requested, we should allow it because it is safe to do it - there's no stale data exposure and we are prepared to compare the data ranges for a length not aligned to the block (or page) size - in fact we even do the data compare before adjusting the deduplication length. After btrfs was updated to use the generic helpers from VFS (by commit 34a28e3 ("Btrfs: use generic_remap_file_range_prep() for cloning and deduplication")) we started to have user reports of deduplication not reflinking the last block anymore, and whence users getting lower deduplication scores. The main use case is deduplication of entire files that have a size not aligned to the block size of the filesystem. We already allow cloning the last block to the end (and beyond) of the destination file, so allow for deduplication as well. Link: https://lore.kernel.org/linux-btrfs/[email protected]/ CC: [email protected] # 5.1+ Reviewed-by: Josef Bacik <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Filipe Manana <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent def9d27 commit a5e6ea1

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

fs/read_write.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,10 +1777,9 @@ static int remap_verify_area(struct file *file, loff_t pos, loff_t len,
17771777
* else. Assume that the offsets have already been checked for block
17781778
* alignment.
17791779
*
1780-
* For deduplication we always scale down to the previous block because we
1781-
* can't meaningfully compare post-EOF contents.
1782-
*
1783-
* For clone we only link a partial EOF block above the destination file's EOF.
1780+
* For clone we only link a partial EOF block above or at the destination file's
1781+
* EOF. For deduplication we accept a partial EOF block only if it ends at the
1782+
* destination file's EOF (can not link it into the middle of a file).
17841783
*
17851784
* Shorten the request if possible.
17861785
*/
@@ -1796,8 +1795,7 @@ static int generic_remap_check_len(struct inode *inode_in,
17961795
if ((*len & blkmask) == 0)
17971796
return 0;
17981797

1799-
if ((remap_flags & REMAP_FILE_DEDUP) ||
1800-
pos_out + *len < i_size_read(inode_out))
1798+
if (pos_out + *len < i_size_read(inode_out))
18011799
new_len &= ~blkmask;
18021800

18031801
if (new_len == *len)

0 commit comments

Comments
 (0)