Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp819401pxb; Thu, 25 Feb 2021 16:29:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJwq4fYO5mkaiqZ8G/5E2HqOL1CzoEkIq4A4jq5ZhtBV5QiLQjo92ZMo5cwlUNtzoJl0/sda X-Received: by 2002:a17:906:654d:: with SMTP id u13mr268882ejn.299.1614299353612; Thu, 25 Feb 2021 16:29:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614299353; cv=none; d=google.com; s=arc-20160816; b=n+pGZQq/BfkkgNBbmt0ynQk3MXcfGLp7yU/uhURC3cFXEXsdcwe8Ns+Df8zQajhkhy dePkQFhQwgF0btCsBQFefbuhjS9A5ybgPk0l7MrfC58/lsexyN0KDDceaL5vbbf19R/g tPXyXwAFvRBndsdK0KqsUFljJgZV2nUKHJNNObUpDa+oU5Gqlsd5PUcV2wHRtWhNJCc0 sVbwaj1FvtON6BDLIZ88zRcuMccVeNvHIRvWg1B2e026HtPn+7O3/D5vQknnQ8loeDFr e1ISm1MdFky5A/dQhjbyr3/r+CVslYlP5gj7GYc5DooowcxOcG1uapcvsz2lyrYM2XQA zMEQ== 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=00/QeQr/85BEZR02eUHSzaQe+o3DeiDn1i3skBwmyMU=; b=UyF0kk7kCaIvco1gCzGV5E2BxpK/73xszZEdyHKwYgRGTgN84L2ksJFpK98Dq/MfK3 aX+Yghwb6h6wnDhNVtzjLlxYwJ29EtrFsx/zNy1a/MDOpT5Xjt8IvjRS7ZUgNUS3hy23 ONcp4kOEcSsdDLaZUf+6Kdc91Vi2dQHcgk9ss1m32cNGb04fOM1IdWlWPES+yTRs45ak 1i4FI206hqYi0iMW4qmnwC+3JezjUsVyVTKpueuH3qiO5YjdPE3fQlg9Dpwn4DeOLIpX GanXNaoJiPPmWc4KD66PS/x8bO4M3t2uvETUivCI6vZCESCASDiMfKdas36Y20bJ1wx3 jBIg== 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 bx16si4198305edb.220.2021.02.25.16.28.50; Thu, 25 Feb 2021 16:29:13 -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 S233245AbhBZA1N (ORCPT + 99 others); Thu, 25 Feb 2021 19:27:13 -0500 Received: from mail.cn.fujitsu.com ([183.91.158.132]:8517 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232806AbhBZA07 (ORCPT ); Thu, 25 Feb 2021 19:26:59 -0500 X-IronPort-AV: E=Sophos;i="5.81,207,1610380800"; d="scan'208";a="104882844" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 26 Feb 2021 08:21:30 +0800 Received: from G08CNEXMBPEKD04.g08.fujitsu.local (unknown [10.167.33.201]) by cn.fujitsu.com (Postfix) with ESMTP id C518C4CE76F6; Fri, 26 Feb 2021 08:21:28 +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 08:21:19 +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 08:21:18 +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 08:20:27 +0800 Message-ID: <20210226002030.653855-8-ruansy.fnst@fujitsu.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210226002030.653855-1-ruansy.fnst@fujitsu.com> References: <20210226002030.653855-1-ruansy.fnst@fujitsu.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-yoursite-MailScanner-ID: C518C4CE76F6.A4A06 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 | 51 +++++++++++++++++++++++++++++++++++++++++++ include/linux/iomap.h | 7 +++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/fs/iomap/apply.c b/fs/iomap/apply.c index 26ab6563181f..fd2f8bde5791 100644 --- a/fs/iomap/apply.c +++ b/fs/iomap/apply.c @@ -97,3 +97,54 @@ 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; + + ret = ops->iomap_begin(ino1, pos1, length, 0, &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; + } + + ret = ops->iomap_begin(ino2, pos2, length, 0, &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; + } + + /* make sure extent length of two file is equal */ + if (WARN_ON(smap.length != dmap.length)) { + written = -EIO; + goto out_dest; + } + + written = actor(ino1, pos1, ino2, pos2, length, data, &smap, &dmap); + +out_dest: + if (ops->iomap_end) + ret = ops->iomap_end(ino2, pos2, length, 0, 0, &dmap); +out_src: + if (ops->iomap_end) + ret = ops->iomap_end(ino1, pos1, length, 0, 0, &smap); + + return ret; +} 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