Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1040232pxb; Fri, 26 Feb 2021 00:31:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJwV7C9qx3wS84TI7oBS5aIu7rwzSsYgP1bCwQDnFReTcEo00vW44bRisYQaohMZKL+1hYDJ X-Received: by 2002:aa7:ca09:: with SMTP id y9mr2075969eds.342.1614328293387; Fri, 26 Feb 2021 00:31:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614328293; cv=none; d=google.com; s=arc-20160816; b=nPP9U3yrGiyB/1vWTKMEzW8sFsMNvPV1doCOFxqGwZrCeHBuBwS1VP7m9ZWu0xYDdi VxSYVcWZj5apCc65AtcGJRoto75Sh40QrbWPZaefuevWKDrEcHLdikatnqwcuPcZ+787 uIBmg76PnrmK5E8tTGStmMMKo7KUy0uj9GSwGIHuQ3x6aEwSpUXz+AGSIQEbmDn3dGdV mNiAL7AQMVwHC8pgkhozenGA8/mypKVH/6GnFv0nWD1Lof5N2kPUxNC07tM2A+7jvdpY 09Y+Z+U9Hf6rQUbDL/sQOtbEfsXSmPyzrrLspMQBf6TjT84k+3MnIg4O86suZxMTTTIP 6Rlw== 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=ZV8gggmvDaL709k1i7/csX6dyyiMVTvsJ5slWT89a5pePF1gjRxmWH++muOAwzTuIj Zv0lneApgF21VNlHrWqQgSF5GCJVC4k6JrMmnfHZkRuFzsIil07hnVxhR3CdJA+u+9TS 8QUg30WU0LwankomkRWAGudrmjZP3OhxE7Cg+8CsbGzS8+nH2S2nDnyH5LRu42YDAi1R 32+UHoTAtfBW47cBpfQq+jOqI3Tr3WnRW5cXmAzWzAQc+uPRawLE8n4cvMoEsYVIWFct uFpch8NFh6BCtZ7mwjGM2vc4ktrDVtgmyGqyh0rQPKZwzh0e1xLpzvDiHQPv6lTE99q2 ubkQ== 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 c13si5411660ede.559.2021.02.26.00.31.11; Fri, 26 Feb 2021 00:31:33 -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 S230014AbhBZI2N (ORCPT + 99 others); Fri, 26 Feb 2021 03:28:13 -0500 Received: from mail.cn.fujitsu.com ([183.91.158.132]:45486 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229618AbhBZI2G (ORCPT ); Fri, 26 Feb 2021 03:28:06 -0500 X-IronPort-AV: E=Sophos;i="5.81,208,1610380800"; d="scan'208";a="104901304" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 26 Feb 2021 16:25:42 +0800 Received: from G08CNEXMBPEKD04.g08.fujitsu.local (unknown [10.167.33.201]) by cn.fujitsu.com (Postfix) with ESMTP id 1D2D24CE7797; Fri, 26 Feb 2021 16:25:40 +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; Fri, 26 Feb 2021 16:25:35 +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; Fri, 26 Feb 2021 16:25:13 +0800 From: Shiyang Ruan To: , , , CC: , , , , , , , , , Subject: [PATCH v2 07/10] iomap: Introduce iomap_apply2() for operations on two files Date: Fri, 26 Feb 2021 16:25:07 +0800 Message-ID: <20210226082507.825238-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: 1D2D24CE7797.A1144 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