Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1248690pxb; Thu, 4 Mar 2021 07:03:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJxfLXrN+kKsOo7ivCKvhUgCTXh/FWMHs4tHi1pgSTSD5qYx25RTUgxgPMOyNqyNdzm1DEk1 X-Received: by 2002:a17:906:3444:: with SMTP id d4mr4734045ejb.410.1614870209829; Thu, 04 Mar 2021 07:03:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614870209; cv=none; d=google.com; s=arc-20160816; b=Bk/qB1s06F1z5ZFa6TdSJ0p1dLDpEec7rre39iQiZWMD2i9vrG5A+WYWuhkxEP2Lsx EK1VmkngCl//jr46Nj3IfIA7r3zXT/veKISXdYxYDbf3UeskJQ/oXYlkKwq992dg2Ivq NBGx1RhEvuUb3SVwxdqPkId7WpFCrpAEhpsVuUw/QrRRtR9M1yw/Ew6cbdYETbOHhBuy lALqy219dwIrLUuiv4i2xjuXBoITvVv7NLF1+EFXahOBmqvIY0B9OsiEGck7eSiNZRZT jCviML0J+lkUsLJsMoeVgPuDaM42FMBd3rDNoQH3xSxP6xK6UTqYReOiS+mbtmUfKHCA 04lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=KBRc9WiFjgDRSv5guqG0/MdQLSkVBbP9X7hEiXcG8O0=; b=tWaOk3qd/sRKjJrEgdRYQrP3xFWvCNGZI3qtgQL5Xe2M/l1FQ6wT/etxg5kI13OlsP 9ZFZ2jVbADYAyqUDMv5NHjCozajeZ8ES+THAvEMiiC5cKc0LGvBkqet9OpaiwWL4SuRw yMKaf5NNLfuqXp7Z19bIUtCwi90J6EcsAxjZkI/HsdiT9BAes2khYcUf+gZARFzHXgha IXgQLc4Nvzcln2wpHKwmswDHGu/weJ2x/FfJ07Ii0PSpNCW+TGtSsIcRPp0pnkxd3ujq 52l12O6/3S9ve3k7Ov2EoO41H8NZ9aemY8Vi31y8SWMbWlRVu5UmJspDXaEd2uYNCR3R 7ufw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p17si16981247edu.119.2021.03.04.07.02.59; Thu, 04 Mar 2021 07:03:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234255AbhCDFo5 (ORCPT + 99 others); Thu, 4 Mar 2021 00:44:57 -0500 Received: from mail.cn.fujitsu.com ([183.91.158.132]:29093 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234236AbhCDFo0 (ORCPT ); Thu, 4 Mar 2021 00:44:26 -0500 X-IronPort-AV: E=Sophos;i="5.81,221,1610380800"; d="scan'208";a="105143058" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 04 Mar 2021 13:42:03 +0800 Received: from G08CNEXMBPEKD04.g08.fujitsu.local (unknown [10.167.33.201]) by cn.fujitsu.com (Postfix) with ESMTP id 8BD674CE92FD; Thu, 4 Mar 2021 13:41:57 +0800 (CST) Received: from G08CNEXCHPEKD04.g08.fujitsu.local (10.167.33.200) by G08CNEXMBPEKD04.g08.fujitsu.local (10.167.33.201) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 4 Mar 2021 13:41:47 +0800 Received: from irides.mr.mr.mr (10.167.225.141) by G08CNEXCHPEKD04.g08.fujitsu.local (10.167.33.209) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 4 Mar 2021 13:41:47 +0800 From: Shiyang Ruan To: , , , CC: , , , , , , , , , Subject: [RESEND PATCH v2.1 07/10] iomap: Introduce iomap_apply2() for operations on two files Date: Thu, 4 Mar 2021 13:41:42 +0800 Message-ID: <20210304054142.1147895-1-ruansy.fnst@fujitsu.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210226002030.653855-8-ruansy.fnst@fujitsu.com> References: <20210226002030.653855-8-ruansy.fnst@fujitsu.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-yoursite-MailScanner-ID: 8BD674CE92FD.A45E2 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: ruansy.fnst@fujitsu.com X-Spam-Status: No Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some operations, such as comparing a range of data in two files under fsdax mode, requires nested iomap_open()/iomap_end() on two file. Thus, we introduce iomap_apply2() to accept arguments from two files and iomap_actor2_t for actions on two files. Signed-off-by: Shiyang Ruan --- fs/iomap/apply.c | 56 +++++++++++++++++++++++++++++++++++++++++++ include/linux/iomap.h | 7 +++++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/fs/iomap/apply.c b/fs/iomap/apply.c index 26ab6563181f..fbc38ce3d5b6 100644 --- a/fs/iomap/apply.c +++ b/fs/iomap/apply.c @@ -97,3 +97,59 @@ iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags, return written ? written : ret; } + +loff_t +iomap_apply2(struct inode *ino1, loff_t pos1, struct inode *ino2, loff_t pos2, + loff_t length, unsigned int flags, const struct iomap_ops *ops, + void *data, iomap_actor2_t actor) +{ + struct iomap smap = { .type = IOMAP_HOLE }; + struct iomap dmap = { .type = IOMAP_HOLE }; + loff_t written = 0, ret, ret2 = 0; + loff_t len1 = length, len2, min_len; + + ret = ops->iomap_begin(ino1, pos1, len1, flags, &smap, NULL); + if (ret) + goto out_src; + if (WARN_ON(smap.offset > pos1)) { + written = -EIO; + goto out_src; + } + if (WARN_ON(smap.length == 0)) { + written = -EIO; + goto out_src; + } + len2 = min_t(loff_t, len1, smap.length); + + ret = ops->iomap_begin(ino2, pos2, len2, flags, &dmap, NULL); + if (ret) + goto out_dest; + if (WARN_ON(dmap.offset > pos2)) { + written = -EIO; + goto out_dest; + } + if (WARN_ON(dmap.length == 0)) { + written = -EIO; + goto out_dest; + } + min_len = min_t(loff_t, len2, dmap.length); + + written = actor(ino1, pos1, ino2, pos2, min_len, data, &smap, &dmap); + +out_dest: + if (ops->iomap_end) + ret2 = ops->iomap_end(ino2, pos2, len2, + written > 0 ? written : 0, flags, &dmap); +out_src: + if (ops->iomap_end) + ret = ops->iomap_end(ino1, pos1, len1, + written > 0 ? written : 0, flags, &smap); + + if (ret) + return written ? written : ret; + + if (ret2) + return written ? written : ret2; + + return written; +} diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 5bd3cac4df9c..913f98897a77 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -148,10 +148,15 @@ struct iomap_ops { */ typedef loff_t (*iomap_actor_t)(struct inode *inode, loff_t pos, loff_t len, void *data, struct iomap *iomap, struct iomap *srcmap); - +typedef loff_t (*iomap_actor2_t)(struct inode *ino1, loff_t pos1, + struct inode *ino2, loff_t pos2, loff_t len, void *data, + struct iomap *smap, struct iomap *dmap); loff_t iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags, const struct iomap_ops *ops, void *data, iomap_actor_t actor); +loff_t iomap_apply2(struct inode *ino1, loff_t pos1, struct inode *ino2, + loff_t pos2, loff_t length, unsigned int flags, + const struct iomap_ops *ops, void *data, iomap_actor2_t actor); ssize_t iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *from, const struct iomap_ops *ops); -- 2.30.1