Some operations, such as comparing a range of data in two files under fsdax mode, requires nested iomap_begin()/iomap_end() on two files. Thus, we introduce iomap_iter2() to accept two iteraters to operate action on two files. Signed-off-by: Shiyang Ruan <ruansy.fnst@xxxxxxxxxxx> --- fs/iomap/core.c | 51 +++++++++++++++++++++++++++++++++++++++++++ include/linux/iomap.h | 2 ++ 2 files changed, 53 insertions(+) diff --git a/fs/iomap/core.c b/fs/iomap/core.c index 89a87a1654e8..214538a25110 100644 --- a/fs/iomap/core.c +++ b/fs/iomap/core.c @@ -77,3 +77,54 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops) iomap_iter_done(iter); return 1; } + +/** + * iomap_iter2 - iterate over a ranges in two files + * @iter1: the first iteration structure + * @iter2: the second iteration structure + * @ops: iomap ops provided by the file system + * + * Iterate two files once. + */ +int iomap_iter2(struct iomap_iter *iter1, struct iomap_iter *iter2, + const struct iomap_ops *ops) +{ + int ret; + + if (iter2->iomap.length && ops->iomap_end) { + ret = ops->iomap_end(iter2->inode, iter2->pos, iomap_length(iter2), + iter2->processed > 0 ? iter2->processed : 0, + iter2->flags, &iter2->iomap); + if (ret < 0 && !iter2->processed) + return ret; + } + + if (iter1->iomap.length && ops->iomap_end) { + ret = ops->iomap_end(iter1->inode, iter1->pos, iomap_length(iter1), + iter1->processed > 0 ? iter1->processed : 0, + iter1->flags, &iter1->iomap); + if (ret < 0 && !iter1->processed) + return ret; + } + + trace_iomap_iter(iter1, ops, _RET_IP_); + ret = iomap_iter_advance(iter1); + if (ret <= 0) + return ret; + ret = iomap_iter_advance(iter2); + if (ret <= 0) + return ret; + + ret = ops->iomap_begin(iter1->inode, iter1->pos, iter1->len, iter1->flags, + &iter1->iomap, &iter1->srcmap); + if (ret < 0) + return ret; + iomap_iter_done(iter1); + + ret = ops->iomap_begin(iter2->inode, iter2->pos, iter2->len, iter2->flags, + &iter2->iomap, &iter2->srcmap); + if (ret < 0) + return ret; + iomap_iter_done(iter2); + return 1; +} diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 24f8489583ca..ebef060c65cd 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -186,6 +186,8 @@ struct iomap_iter { }; int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops); +int iomap_iter2(struct iomap_iter *iter, struct iomap_iter *iter2, + const struct iomap_ops *ops); /** * iomap_length - length of the current iomap iteration -- 2.32.0