aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShiyang Ruan <[email protected]>2022-12-01 15:31:41 +0000
committerAndrew Morton <[email protected]>2022-12-11 18:12:16 -0800
commit0e79e3736d54bb8efbc9fb29cc3b54a132783565 (patch)
tree0003059835fda355a1878373412fded18170d916
parentc6f0b395b2110aa26a134a9a395875b1ec0a5aae (diff)
fsdax: dedupe: iter two files at the same time
The iomap_iter() on a range of one file may loop more than once. In this case, the inner dst_iter can update its iomap but the outer src_iter can't. This may cause the wrong remapping in filesystem. Let them called at the same time. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Shiyang Ruan <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Cc: Alistair Popple <[email protected]> Cc: Dan Williams <[email protected]> Cc: Dave Chinner <[email protected]> Cc: Jason Gunthorpe <[email protected]> Cc: John Hubbard <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
-rw-r--r--fs/dax.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/fs/dax.c b/fs/dax.c
index fa547ce41add..8fb928cd9dce 100644
--- a/fs/dax.c
+++ b/fs/dax.c
@@ -1965,15 +1965,15 @@ int dax_dedupe_file_range_compare(struct inode *src, loff_t srcoff,
.len = len,
.flags = IOMAP_DAX,
};
- int ret;
+ int ret, compared = 0;
- while ((ret = iomap_iter(&src_iter, ops)) > 0) {
- while ((ret = iomap_iter(&dst_iter, ops)) > 0) {
- dst_iter.processed = dax_range_compare_iter(&src_iter,
- &dst_iter, len, same);
- }
- if (ret <= 0)
- src_iter.processed = ret;
+ while ((ret = iomap_iter(&src_iter, ops)) > 0 &&
+ (ret = iomap_iter(&dst_iter, ops)) > 0) {
+ compared = dax_range_compare_iter(&src_iter, &dst_iter, len,
+ same);
+ if (compared < 0)
+ return ret;
+ src_iter.processed = dst_iter.processed = compared;
}
return ret;
}