Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp373183pxf; Thu, 8 Apr 2021 05:07:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxikvlsyR5WOc7iW2Js/BP71bCUVKTbCpkCpXxRyUAMHSQOXExpw1dejVZR0t8kY2ohEe93 X-Received: by 2002:a05:6402:1393:: with SMTP id b19mr10810938edv.333.1617883624787; Thu, 08 Apr 2021 05:07:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617883624; cv=none; d=google.com; s=arc-20160816; b=A5wuOP0lQYtr44fSjdskm1+6Ox1VOQeKbipJs7Z/hIV8xTLT9cuRD+HUAybD7HYtaY gv/iq0MMdRwj0U52Nvy1GtbIrfVQZ9IsQY+OcVkeLhrFkMup6AHW/6ewnwP2FFXmbB3P pvlAU8Z25qsrkb+q3xFoivAHdncBm+Q32EfJYruY1p9xXQU0vQQb1qiSKTCM5IFlV9ZM u3s8WCbyhVxdeQpGSkWhDtuqw1mtEH9i/wR1vEHlSnwH3h3fRExG9xI9nO7IpAJr1Zzo t4V4UIGOYiIPaO3OXxUGPAuhr9LWUl89ORWPf0YQQ02buwq8Gn30TzjdbO1PqKuTrrxL kPUg== 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 :ironport-hdrordr; bh=1TIAzuXNpJjuh1UiikudT08+aXubj2YGJDR5tfcDqlQ=; b=kJhp9nkU5VezEqRjb3WhANR9xSxbmIIz0wWZhKS/PJ45SLSBHP5Kugm2bWgFoytYiM jO3u9o0Icfl90hW91MXB1h2GzRBaEPlUQfPSJAQpE6dhJcUIya/ZeEn+AR8o6Wjw5wXf JQekNa8Vm7xi8IAtqet/j9AaT5Z27xfjv7yqxUFmsND7FJqKT8n3VnI8K6osC3CNE8NU bzgJJcpuosYH0gmVUg5oYtjk3fjb/hHh+azTK2KFr2RiadNlkfGneRH22Ru7oFC2LiJD iwl95cD2KlkqZK100wphDdA2iS2hiFfmtBYIyScKyeo/PUNiEh2K5fK4vNKywxc4Xqpy cAgA== 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 dt15si3848554ejc.504.2021.04.08.05.06.41; Thu, 08 Apr 2021 05:07:04 -0700 (PDT) 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 S231534AbhDHMF0 (ORCPT + 99 others); Thu, 8 Apr 2021 08:05:26 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:24855 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231513AbhDHMFX (ORCPT ); Thu, 8 Apr 2021 08:05:23 -0400 IronPort-HdrOrdr: =?us-ascii?q?A9a23=3AEs1dYKNTetm8FsBcTiGjsMiAIKoaSvp033AA?= =?us-ascii?q?0UdtRRtJNvGJjszGpoV+6TbYqhY0HEshl9eJJbWaTRrnmKJdzIENMd6ZMjXOl2?= =?us-ascii?q?elIYpr54mn4xCIIUfD38FH06MISclDIfnRKXQ/ssrg+gm/FL8bsby62YSln/3X?= =?us-ascii?q?wXsobSwCUdAC0y5DBgyWElJ7SWB9bPJXKLOn+sFFqzC8EE5nDPiTO39tZYj+ju?= =?us-ascii?q?yOvJfnTDpDPBQ/9TSJ5AnC1JfKVzSewTcSOgki/Ysf?= X-IronPort-AV: E=Sophos;i="5.82,206,1613404800"; d="scan'208";a="106797297" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 08 Apr 2021 20:05:11 +0800 Received: from G08CNEXMBPEKD04.g08.fujitsu.local (unknown [10.167.33.201]) by cn.fujitsu.com (Postfix) with ESMTP id 969E04D0B8A3; Thu, 8 Apr 2021 20:05:05 +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, 8 Apr 2021 20:05:00 +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, 8 Apr 2021 20:05:00 +0800 From: Shiyang Ruan To: , , , CC: , , , , , , , , Subject: [PATCH v4 4/7] iomap: Introduce iomap_apply2() for operations on two files Date: Thu, 8 Apr 2021 20:04:29 +0800 Message-ID: <20210408120432.1063608-5-ruansy.fnst@fujitsu.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210408120432.1063608-1-ruansy.fnst@fujitsu.com> References: <20210408120432.1063608-1-ruansy.fnst@fujitsu.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-yoursite-MailScanner-ID: 969E04D0B8A3.A1BFB 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 | 52 +++++++++++++++++++++++++++++++++++++++++++ include/linux/iomap.h | 7 +++++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/fs/iomap/apply.c b/fs/iomap/apply.c index 26ab6563181f..0493da5286ad 100644 --- a/fs/iomap/apply.c +++ b/fs/iomap/apply.c @@ -97,3 +97,55 @@ 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; + 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_src; + 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); +out: + if (written) + return written; + return ret ?: ret2; +} diff --git a/include/linux/iomap.h b/include/linux/iomap.h index d202fd2d0f91..9493c48bcc9c 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -150,10 +150,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.31.0